Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i change two local values when i touch a part?

(Sorry, my english isnt that good) I already asked about this and someone provided me whit the script but... Me and my friend have different values (thats ok, i joined first, he second) But then my friend touches the part and our values are set (Thats not supposed to happen, only my friend value should be set), so how do i detect who is touching the part and how do i change the values for that person? Here is the code that he provided to me, but a bit changed.

 game.Workspace.Part.Touched:Connect(function()
	game.Players.LocalPlayer.PlayerGui.Value1.Value = 100
	game.Players.LocalPlayer.PlayerGui.Value2.Value = 0
end)

5 comments

0

You shouldn’t use a local script for a touched script. Use a server script and just get the player from the character, then change their values from there

0

How? Im kinda new at scripting

0

You would need to add a parameter to the function so like function(hit) and then do player = game.Players:GetPlayerFromCharacter(hit.Parent) and then you can do player.PlayerGui.Value1.Value = 1

0

I realy dont understand, could you show me how? Sorry if i annoy you.

0

Naw you’re all good dude

1 answer

✓ Accepted answer
game.Workspace.Part.Touched:Connect(function(hit))
    if hit.Parent:FindFirstChild(“Humanoid”) then
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    player.PlayerGui.Value1.Value = 100
    player.PlayerGui.Value2.Value = 0
    end
end)

Make sure this is in a normal script, and most conveniently in the brick you are touching.

What the FindFirstChild is doing is checking that the thing that touched it is a character, and not just some random part that has no humanoid in it.

You then get the player from their character, and set that as a variable, and in this case I called it player.

After that, you simply go to where the value you want to change is located, and change it from there.

I hope this helped, and if it did please accept the answer :)

5 comments

0

Sorry for taking a while to anwer but it isnt working.

0

This is weird, the script seems to work but the value part doesnt. How do i know that? Basicly i replaced the player.PlayerGui.Value1.Value whit print("text") and the text prits

0

Okay, so this is weirder, seems like the script works once, like, value1 = 10, i step on the block and it turns to 100, then

0

value1 = 10, i step on the block again and it doesnt work

0

Im going to mark the answer, since it kinda works, but i will find help in the discod server to make it always work.

This discussion is preserved as it was. New answers, comments, and votes are closed.