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

Anyone know how to switch two players GUI Values?

Asked by 3 years ago

I am currently scripting a game where you collect a bunch of Marbles and each time you collect a marble, there is a Textlabel inside the Players Gui called 'Number' and its text will go up by 1. So far this bit works fine. However I am implementing a tool that allows you to swap you and another players marble number. I plan to do this by colliding the tool's handle with another player, and switching their TextLabel's text values. This is the script I've placed inside the tool's handle.


script.Parent.Touched:connect(onTouched) function onTouched(hit) if hit.Parent:findFirstChild("Humanoid") then local h = hit.Parent:findFirstChild("Humanoid") if h ~= nil then local player = game.Players:GetPlayerFromCharacter(h.Parent) local salad = player.PlayerGui["Marble Counter"].Number.Text local dog = script.Parent.Parent.Parent:FindFirstChild("Humanoid") if dog ~= nil then local player1 = game.Players:GetPlayerFromCharacter(dog.Parent) local salad1 = player1.PlayerGui["Marble Counter"].Number.Text salad = salad1 salad1 = salad end script.Parent.Parent:Destroy() end end end

Sorry if this script is messy I'm relatively new to scripting. The Output shows that when I pick up the tool and hold it there is 'Attempt to connect failed: Passed value is not a function' and when I collide with another player it outputs 'attempt to call a nil value'

If anyone knows where in this script things are going wrong or a different method of writing this that works it would be much appreciated.

Answer this question