So I have a part which when is touched a gui is shown, i tried my script but it didnt work and also didnt give any errors , any reason why?
local ebutton = button.eButton
function you(hit)
if hit.Parent:FindFirstChild("Humanoid") then
button.Visible = true
ebutton.Visible = true
end
end
script.Parent.Touched:Connect(you)
Where is button defined?? Is this in StarterCharacterScripts or StarterGui. Either ways its better practice to get that players ui from the PlayerGui.
function hitPart(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local UI = player.PlayerGui.Frame.YourUI
UI.visible = true
end
end
part.Touched:Connect(hitPart)
You can’t access the Player GUI from the Server Script unless it was fired from the Client, In this case, you’re using Touched event, But you can still get the Player.
By following this method;
function you(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
plrGui = plr.PlayerGui
--Make the Code here to make the GUI Enable
end
end
script.Parent.Touched:Connect(you)
local Part = game.Workspace["YOUR PART HERE"]
local Gui = script.Parent -- This means the script is parented already into the gui than getting it into the PlayerGui
local function OnTouched(Object)
if game.Players:GetPlayerFromCharacter(Object.Parent) then
Gui.Visible = true
end
end
Part.Touched:Connect(OnTouched)