Hey everyone, so today I was working on a little script for practice, and I came up on this problem, when I click the part, the screengui should enable again and the text pops up with the name of the person that clicked it, I am not sure how to fix this because it doesn’t work. There are no errors. I think I’m suppose to use playergui, just not sure how. Here is my script.
--//Variables//--
local plr = game.Players.LocalPlayer
local screengui = game.StarterGui.ScreenGui
local txt = game.StarterGui.ScreenGui.TextLabel
local button = game.Workspace.button
--//Main Code//--
button.ClickDetector.MouseClick:Connect(function(hit)
if hit.Parent == plr and screengui.Enabled == false then
screengui.Enabled = true
txt = (hit.Parent.. "Touched the Button!")
end
end)
if anyone knows how to fix this, please let me know, thanks!
Hi! So for the MouseClick event function it passes along the player variable already, so if you want the players name you can just do hit.Name to get there string name for it! you have your screengui targeting the one in StarterGui . So if the script is the child of the UI itself then I would just do script.Parent for the screengui variable
Isn’t the hit parameter a player instance? And also you can just use local player = hit:GetPlayerFromCharacter() to turn the hit parameter into a character
EDIT: Nevermind im dumb you were talking about the gui
Ok so I removed the screengui variable and made it enabled and made the background 1, so I made the text not visible, but it still does not work. Do you know why? here is my changed script…
--//Variables//--
local plr = game.Players.LocalPlayer
local txt = game.StarterGui.ScreenGui.TextLabel
local button = game.Workspace.button
--//Main Code//--
button.ClickDetector.MouseClick:Connect(function(hit)
if hit.Parent == plr and txt.Visible == false then
txt.Visible = true
txt = hit.Name.. "Touched the Button!"
end
end)
I changed it again, I removed the if hit.Parent == plr. I changed it to if txt.Visible == false then, I made a print thing to see if it ran, it printed but nothing happened after.
--//Variables//--
local plr = game.Players.LocalPlayer
local txt = game.StarterGui.ScreenGui.TextLabel
local button = game.Workspace.button
--//Main Code//--
button.ClickDetector.MouseClick:Connect(function(hit)
if txt.Visible == false then
print("It's Visible!")
txt.Visible = true
txt = hit.Name.. "Touched the Button!"
end
end)
again Like I stated in my first post StaterGui will not change anything for the PlayerGui which is what gets replicated to the player on join/respawn. Changing the name of the variable will not change much, can you show me what the explorer looks like so I can help with the hierarchy
local plr = game.Players.LocalPlayer
local txt = script.Parent.TextLabel
local button = game.Workspace.button
--//Main Code//--
button.ClickDetector.MouseClick:Connect(function(hit)
if txt.Visible == false then
print("It's Visible!")
txt.Visible = true
txt = hit.Name.. "Touched the Button!"
end
end)