Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Players Gui wont change?

Asked by 10 years ago

I cant figure out whats wrong with this. Just trying to change the players Gui when you walk on it thats it.

script.Parent.Touched:connect(function(player)
    player.PlayerGui.Checkpoint.Point.Text = 1
end)

Says PlayerGui is not a valid member of Part. Help please? And this is basically a code that I got off this site before with one of my other questions, can someone explain how this function works too? Like why is it like

script.Parent.Touched:connect(function(player)

and not

function something(player)

Whats the difference between the two? Thanks a ton.

2 answers

Log in to vote
2
Answered by 10 years ago

You have a few problems here.

script.Parent.Touched:connect(function(part) --This is the PART that touched it, not the player.
    if not part.Parent:FindFirstChild("Humanoid") then return end --Checks if it's ACTUALLY a character
    player = part.Parent:GetPlayerFromCharacter() --NOW we can access the player using the following line.
    player.PlayerGui.Checkpoint.Point.Text = 1
end)

Also, using that one-liner is called an anonymous function. It cuts down your script total lines by 1, so it's a more efficient script.

I'm Aurum, and you're welcome.

Ad
Log in to vote
1
Answered by
lomo0987 250 Moderation Voter
10 years ago

You have few things wrong.. I will explain in the script..

script.Parent.Touched:connect(function(player) -- 'player' is the part that touches it, nothing else.. So it's either going to be the Left Leg or the Right Leg of the player..
plr = game.Players:FindFirstChild(player.Parent.Name) -- This is going to get the player itself
    plr.PlayerGui.Checkpoint.Point.Text = 1 -- now this will change the GUI for the player.
end)

As for your 2nd question the difference from

script.Parent.Touched:connect()

and..

script.Parent.Touched:connect(function(player)
end)

The first one is going to connect the function that's defined like this..

function CheckPoint (player)
--Code
end

How you would activate it is like this..

function CheckPoint (Player)
--Code
end

script.Parent.Touched:connect(CheckPoint) -- you put the name of the function in ().

I hoped this helped, please +1 if it did!

Answer this question