I have successfully created a spawn script that allows you to go in proximity of a guy andthen u can spawn a jeep, but when I team-tested it when I went in proximity everyon got the UI up on their screen too! I don’t know why, can anyone help?
My Script:
local folder = game.Workspace.VehicleSpawn1
game.Players.PlayerAdded:Connect(function(plr)
script.Parent.Touched:Connect(function(hit)
if plr:GetRankInGroup(33488955) >= 30 then
plr.PlayerGui.CarSpawn1.Frame.Visible = true
end
end)
script.Parent.TouchEnded:Connect(function(hit)
plr.PlayerGui.CarSpawn1.Frame.Visible = false
end)
end)
that line always fires for every player that joined when the part is touched. You need to implement a check to know if the player who touched the part is the player you got from playeradded
script.Parent.Touched:Connect(function(hit) -- Detects a hit
if hit:FindFirstChild("Humanoid") then -- Detects if 'hit' has a Humanoid
local player = game.Players:FindFirstChild(hit.Parent.Name) -- Gets the player
if player:GetRankInGroup(33488955) >= 30 then -- Gets player group role
player.PlayerGui.CarSpawn1.Frame.Visible = true -- Enables UI
end
end
end)
script.Parent.TouchEnded:Connect(function(hit) -- Don't need to check if in group because it doesn't matter if the don't see the UI
if hit:FindFirstChild("Humanoid") then
local player = game.Players:FindFirstChild(hit.Parent.Name)
player.PlayerGui.CarSpawn1.Frame.Visible = false -- Disables UI
end
end)
Tell me if this works. I just came up with it in about 5 mins
script.Parent.Touched:Connect(function(hit) -- Detects a hit
if hit:FindFirstChild("Humanoid") then -- Detects if 'hit' has a Humanoid
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player
if player:GetRankInGroup(33488955) >= 30 then -- Gets player group role
player.PlayerGui.CarSpawn1.Frame.Visible = true -- Enables UI
end
end
end)
script.Parent.TouchEnded:Connect(function(hit) -- Don't need to check if in group because it doesn't matter if the don't see the UI
if hit:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.PlayerGui.CarSpawn1.Frame.Visible = false -- Disables UI
end
end)
You still didn’t answer if this was a server script or a local script.
What are the outputs of the print statements I suggested? I just gave one example, but if you print those variables you can see what values each if statement is reacting to for the section of code you deal with.