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

Why this script dont changes the text and background of button?

Output says: PlayerGui is not a valid member of MeshPart "Workspace.SashaPro336.LeftHand" The Script:

script.Parent.Touched:Connect(function(plr)
	plr.PlayerGui.Service.PortalsFrame.Winterland.Text = "Teleport"
	plr.PlayerGui.Service.PortalsFrame.Winterland.BackgroundColor3 = Color3.fromRGB(62, 255, 33)
end)

1 answer

✓ Accepted answer

The 'plr' value you have is referencing the part that touched whatever the script was listening to, using it doesn't directly lead you to the player that touched the part so you'll have to make some edits.

There exists a function in game.Players called 'GetPlayerFromCharacter' which you can use to find a player from their player model, which we would find with plr.Parent because the parent of the body parts is the player model. Just to make sure it doesn't break we make sure that plr.Parent is a model so it doesn't send something incorrect, along with other checks as you'll see.

script.Parent.Touched:Connect(function(plr)
	if plr.Parent:IsA("Model") and game.Players:FindFirstChild(plr.Parent.Name) then
		if game.Players:GetPlayerFromCharacter(plr.Parent) then
			plr=game.Players:GetPlayerFromCharacter(plr.Parent)
			plr.PlayerGui.Service.PortalsFrame.Winterland.Text = "Teleport"
			plr.PlayerGui.Service.PortalsFrame.Winterland.BackgroundColor3 = Color3.fromRGB(62, 255, 33)
		end
	end
end)

Let me know if something is wrong with the code, I can't actually test it.

5 comments

0

Thanks!

0

Bro, what to do when player dies the text and background color is turining back? How to make text changed forever to teleport?

0

can you help me with it?

0

So can you help me with it?

0

The problem is that the UI you get is from StarterGui and it reloads every time you spawn, so the text and color changes back since it was never changed in StarterGui. Honestly it would take a good bit of tinkering to fix that

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