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

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

Asked by 2 years ago

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

Log in to vote
0
Answered by
EmK530 143
2 years ago
Edited 2 years ago

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.

0
Thanks! SashaPro336 47 — 2y
0
Bro, what to do when player dies the text and background color is turining back? How to make text changed forever to teleport? SashaPro336 47 — 2y
0
can you help me with it? SashaPro336 47 — 2y
0
So can you help me with it? SashaPro336 47 — 2y
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 EmK530 143 — 2y
Ad

Answer this question