So i want to make a gui appearing for a certain player that touched a part and i am getting a weird output.
Apparently when player1 touches the part player2 client outputs "PlayerGui is not a valid member of Player “Players.Player1"”
local script detecting if player touched the part it’s inside screenGui in starterGui
local brick = workspace.ShopOwner
local RESET_SECONDS = 2
local isTouched = false
brick.Touched:Connect(function(hit2)
wait(0.1)
if hit2 and hit2.Parent:FindFirstChild("Humanoid") then
local player = game:GetService("Players"):GetPlayerFromCharacter(hit2.Parent)
if not isTouched then
isTouched = true
player.PlayerGui.Ownershop.Frame.Visible = true
wait(RESET_SECONDS)
isTouched = false
end
end
end)
I tried changing the code and putting it as a server script inside the part but i had the same output.
just tried that it seems to work only once then it’s not working anymore
That’s the local script for closing the gui inside the gui button
function leftClick()
local plr = game:GetService("Players").LocalPlayer
local camera = game.Workspace.Camera
camera.CameraType = Enum.CameraType.Custom
plr.Character.Humanoid.WalkSpeed += plr.WlkSpd.Value
script.Parent.Parent.Visible = false
wait(0.1)
script.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:Connect(leftClick)
When you say it only works once but doesn’t work anymore, do you mean like the Gui pops up once but not again? Are you receiving any errors from the output?
local brick = workspace.ShopOwner
local RESET_SECONDS = 2
local isTouched = false
brick.Touched:Connect(function(hit2)
wait(0.1)
if hit2 and hit2.Parent:FindFirstChild("Humanoid") then
local player = game:GetService("Players"):GetPlayerFromCharacter(hit2.Parent)
if not isTouched then
isTouched = true
player:WaitForChild("PlayerGui").Ownershop.Frame.Visible = true
wait(RESET_SECONDS)
isTouched = false
end
end
end)
and this is inside a button local script
function leftClick()
local plr = game:GetService("Players").LocalPlayer
local camera = game.Workspace.Camera
camera.CameraType = Enum.CameraType.Custom
plr.Character.Humanoid.WalkSpeed = plr.WlkSpd.Value
script.Parent.Parent.Visible = false
wait(0.1)
script.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:Connect(leftClick)
i analysed it few times and i couldnt find anything wrong
Try this if it doesn’t work please tell me the error.
Also I recommend firing a RemoteEvent when the Player touchs the Brick then making the Frame visible inside the Local Script That also might be the issue try this first if it doesn’t work then fire a remote event when the Player touchs the Brick then making the frame visible inside the Local script.
local brick = game.workspace.ShopOwner
local RESET_SECONDS = 2
local isTouched = false
brick.Touched:Connect(function(hit2)
wait(0.1)
if hit2.Parent:FindFirstChild("Humanoid") then
local player = game:GetService("Players"):GetPlayerFromCharacter(hit2.Parent)
if isTouched == false then
isTouched = true
player:FindFirstChild("PlayerGui").Ownershop.Frame.Visible = true
wait(RESET_SECONDS)
isTouched = false
end
end
end)
It looks like this is a server script. Since everything from the sever always loads in before stuff from the client you should at a :WaitForChild() for the PlayerGUI since it might not have loaded in yet.
Remote Events then once its fired to sevrer fire player 2’s client
example
server
local remote = script.Parent.RemoteEvent
local part = workspace.ShopOwner
part.Touched:Connect(function(target)
if target:FindFirstChild("Humanoid") then
local targetsplayer = game:GetService("Players"):WaitForChild(target.Name)
remote:FireClient(targetsplayer)
end
end)
client
local remote = script.Parent.RemoteEvent
remote.OnClientEvent:Connect(function()
game.Players.LocalPlayer.PlayerGui.GUI_FRAME_WHATEVER.Visible/Enabled = true
end)