This doesn't work for some reason. No output. I think it's because I am using "LocalPlayer" to find the player that touched the part. Any ways to fix this?
function onTouch() game.Players.LocalPlayer.PlayerGui.ScreenGui.Script.Disabled = false game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true game.Players.LocalPlayer.PlayerGui.ScreenGui.ImageLabel.Visible = true game.Players.LocalPlayer.PlayerGui.End:Play() end script.Parent.Touched:connect(onTouch)
function touch(plr) player = game.Players:FindFirstChild(plr.Name) -- Code.. end
What I do to get the player that has touched a brick is this..
function touch(plr) player = game.Players:FindFirstChild(plr.Name) -- Code.. end
Local Player only works in local scripts that are located somewhere inside the player such as PlayerGUI (StarterGUI) or the BackPack. (i don't know the names for that exactly, I would have to check.)
Is this in a Script or a LocalScript? Now, rather than using LocalPlayer, find the player who hit the part.
function onTouch(hit) if hit and hit.Parent.Character then hit.Parent.PlayerGui.ScreenGui.Script.Disabled = false hit.Parent.PlayerGui.ScreenGui.Frame.Visible - true hit.Parent.PlayerGui.ScreenGui.ImageLabel.Visible = true hit.Parent.Playergui.End:Play() end end script.Parent.Touched:connect(onTouch)
The only reason the code I provided wouldn't work is if I got the hierarchy of the hit
wrong, which is possible.
Fixed it myself:
function onTouch(plr) player = game.Players:GetPlayerFromCharacter(plr.Parent) player.PlayerGui.ScreenGui.Script.Disabled = false player.PlayerGui.ScreenGui.Frame.Visible = true player.PlayerGui.ScreenGui.ImageLabel.Visible = true player.PlayerGui.End:Play() end script.Parent.Touched:connect(onTouch)