I wanted to make a script where when a player touches a part a gui appears for the player who touched it but I can't I tried the script.
`script.Parent.Touched:Connect(function(hit) if hit.parent:FindFirstChild("Humanoid") then local blue = hit.Parent game.StarterGui.Nice.Frame.Visible = true end end)
Sadly, it wont work, I searched it on the internet but none of them explained properly or I couldn't find it. Please help me make it work. Thank you if you do.
You requested the script for situation to show the GUI only when the player is touching the part. This is still a Local Script so put it inside your GUI.
local Workspace = game.Workspace local Tpart = Workspace:WaitForChild("Part") -- Defines a way to a part. local Players = game:GetService("Players") -- Code starts here local deb = 0 -- Makes the frame visible Tpart.Touched:Connect(function(hit) if deb == 0 then deb = 1 local char = hit.Parent if char then local hum = char:WaitForChild("Humanoid") if hum ~= nil then print("Opening the Gui") local Player = Players:GetPlayerFromCharacter(char) local PlayerGui = Player.PlayerGui local GuiToBeOpened = PlayerGui:WaitForChild("Nice") GuiToBeOpened.Frame.Visible = true end end end end) -- ?? Disappears the frame Tpart.TouchEnded:Connect(function(hit) if deb == 1 then deb = 0 local char = hit.Parent if char then local hum = char:WaitForChild("Humanoid") if hum ~= nil then print("Opening the Gui") local Player = Players:GetPlayerFromCharacter(char) local PlayerGui = Player.PlayerGui local GuiToBeOpened = PlayerGui:WaitForChild("Nice") GuiToBeOpened.Frame.Visible = false end end end end)
The StarterGui is the placeholder for the GUIs to be loaded later on for the different players.
Assuming by this "oopsie", I suppose that you are not very experienced into programming, so I'll keep the answer simple for you:
script.Parent.Touched:Connect(function(hit) -- Checking if it's a character(by having a humanoid) local hum = hit.Parent:FindFirstChild("Humanoid") if(hum) then -- method used to find the player local player = players:GetPlayerFromCharacter(Hum.Parent) if(player) then local gui = player.PlayerGui("Nice") -- your GUI's name gui.Frame.Visible = true end end end)
When the player loads, the GUI is no longer inside of "StarterGui", but in "PlayerGui", found as a child of the player.