Hello, im trying to make a script in which when you stand on top of a part it makes a text button appear. Its a local script and the directory of it is Workspace\Part\LocalScript, and the directory of the text button is StarterGui\ScreenGui\TextButton. Here is the code:
local player = game.Players.LocalPlayer local function Touched(hit) if hit.Parent:FindFirstChild("Humanoid") then player.PlayerGui.ScreenGui.TextButton.Visible = true end end script.Parent.Touched:Connect(Touched)
You've already got the basics in place but your issue is stemming from determining whether the part that touched the other part is a member of a Characters model.
local player = game.Players.LocalPlayer
will only work when using a LocalScript and in this instance, you are using a ServerScript so this should be changed to just local Players = game.Players
.
To fix this, you can use the GetPlayerFromCharacter
method like this
local player = Players:GetPlayerFromCharacter(hit.Parent)
After which you can check whether the method returned a Player.
if player ~= nil then end
Putting it altogether will get you:
local Players = game.Players local function Touched(hit) local player = Players:GetPlayerFromCharacter(hit.Parent) if player ~= nil then player.PlayerGui.ScreenGui.TextButton.Visible = true end end script.Parent.Touched:Connect(Touched)