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

Script that shows a Text Button when im standing on a part doesnt work, no errors or outputs?

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)

2 comments

0

have you tried debugging it by adding a print to every thread?

0

yes, i have but no prints work, not even before the local player variable

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you for the help!

0

No problem!

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