#i cant get a simple button to work

50 messages · Page 1 of 1 (latest)

woeful pawn
#

i've been trying to get into coding, and i thought that getting my character to jump or sit with a button would be simple. but i just cant get it to work, i've tried every source, this server, google, reddit, nothing helps

#

here's my code

#

local button = script.Parent
local players = game:GetService("Players")
local function sit ()
local player = players.LocalPlayer
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Sit = true
end
end
end
button.MouseButton1Click:Connect(sit)

woeful pawn
#

no, the code's clean, but when i click the button nothing happens

runic moth
woeful pawn
#

no, im still very new, how do i do that?

runic moth
#

View-> output

#

In the top bar on studio

woeful pawn
#

oh dang, i didnt know about this

runic moth
#

Any red lines when running?

woeful pawn
#

i got this: Players.maykonrbds1.PlayerGui.ScreenGui.sit button.Script:5: attempt to index nil with 'Character'

#

it was red

woeful pawn
#

yes

balmy minnowBOT
#

studio** You are now Level 1! **studio

runic moth
#

mind telling me the color of the script icon?

woeful pawn
#

its white

#

i also tried using local script, that didnt work

runic moth
#

Copy the code (the text), delete the script

#

Then add in a local script

runic moth
woeful pawn
#

alr

#

im going to try that

runic moth
#

But let’s first change it over to a local script

#

Then run it again and tell me the next error

woeful pawn
#

omg

#

it worked

#

i know its not your job, but could you tell me the difference between local script and just script?

runic moth
#

You have the server and the client. Server scripts run only on the server, these can’t be altered by players but also can’t take inputs as easily

#

Local scripts run per client. These will add some things for one to take inputs (e.g. pressing a button). This will also add the ability to use .LocalPlayer

woeful pawn
#

im still pretty confused, but i think i get it

#

honestly, just being able to see the output of my scripts is already very helpfull

#

thank you very, very much!

runic moth
#

A hint: the most common error you’ll encounter is

blabla attempted to index nil with X

This means you have a line like

…Y.X…

This does NOT mean X doesn’t exist, this means Y doesn’t exist

#

Very common mistake but very useful to know

woeful pawn
#

im sure that'll make more sense as i get used to scripting, but thx

runic moth
#

It will make more sense when you encounter it

woeful pawn
#

alr, im going to go back to messing around in roblox studio, this helped a lot, thank you

#

8 hours of trying to get a code to work, and all i needed was to change 1 simple thing

runic moth
#

It will get better

jade kindle
# woeful pawn im still pretty confused, but i think i get it

Ok so think of it this way:

Local script is like on the side of your device. It is to do with YOUR player and can interact with your player and what it does. Eg. Game.Players.LocalPlayer:Kick(“Haha get better”) - the script only works on a local script, because it is dealing with the client, your account.

A script is what deals with server-wide events that may affect every player. Eg: local NewPart = Instance.new(“Part”) - it only works on server side, as it is to do with EVERYONE

TL;DR: local script = you. Normal script = server

#

Pro tip: if something isn’t working, after every line or block of code, do print(“[what you are trying to accomplish goes here] completed”)

For example if I was doing a script that makes a part bigger I might do this -

local function MakePartBigger()
— code goes here
End
Print(“MakePartBigger Successful”)

runic moth
jade kindle