#i cant get a simple button to work
50 messages · Page 1 of 1 (latest)
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)
Any errors?
no, the code's clean, but when i click the button nothing happens
Do you have the output open?
no, im still very new, how do i do that?
oh dang, i didnt know about this
Any red lines when running?
i got this: Players.maykonrbds1.PlayerGui.ScreenGui.sit button.Script:5: attempt to index nil with 'Character'
it was red
Do you have the explorer open?
yes
** You are now Level 1! **
mind telling me the color of the script icon?
Probably some different error then
But let’s first change it over to a local script
Then run it again and tell me the next error
omg
it worked
i know its not your job, but could you tell me the difference between local script and just script?
Well it’s mainly the runcontext
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
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!
Oh it is. Only real way you know what’s wrong with it
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
im sure that'll make more sense as i get used to scripting, but thx
Just remember it the next time you see that error
It will make more sense when you encounter it
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
When I first started programming I once took 12 hours on a 3 line code
It will get better
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”)
That print should be located i side the function, else it doesn’t print when the function finishes. It now prints when the function gets declared (functions first get declared and later get called (which is when they run))
Oh yes, my bad
I have been coding for years, I’m still not good