So I have this script that when you sit, it gives you A gui, but for some reason it gives me a way higher ammount than 1, random numbers. Any help?
local PlayerService = game:GetService("Players") -- get playerservice
script.Parent.Changed:Connect(function(newvalue) -- setup a function connected to the Changed event with a newvalue arg
if not script.Parent.Occupant then return end -- make sure the change was an occupant
local Player = PlayerService:GetPlayerFromCharacter(script.Parent.Occupant.Parent) -- get the player
if not Player then return end -- check if player is nil (maybe an npc sat down idk)
if Player.Name == script.OwnerName.Value then -- check if its the owner
local dog = script.CarGui:Clone()
dog.Parent = Player.PlayerGui
else -- if it isn't
script.Parent.Occupant.Jump = true -- make them jump
end -- close if statement
end) -- close function
I got put prints, and it repeats the ENTIRE script, so something in the parent must be changing more than once? I could try to put a wait() for like 3 seconds possibly?
Something is changing in your scripts it seems like, so yes I would put in a wait() at the top of your function. (maybe 3 seconds is good), see if it works.
So I tried this, but now its just completely stopped working.
local PlayerService = game:GetService("Players") -- get playerservice
rat = false
script.Parent.Changed:Connect(function(newvalue)
if rat == false then
rat = true
local Player = PlayerService:GetPlayerFromCharacter(script.Parent.Occupant.Parent) -- get the player
print("got player")
if Player.Name == script.OwnerName.Value then -- check if its the owner
print("checked player name")
local dog = script.CarGui:Clone()
print("cloned gui")
dog.Parent = Player.PlayerGui
print("gave gui")
wait(2)
rat = false
else -- if it isn't
script.Parent.Occupant.Jump = true -- make them jump
end
end -- close if statement
end) -- close function
local PlayerService = game:GetService("Players") -- get playerservice
rat = false
script.Parent.GetPropertyChangedSignal("Occupant"):Connect(...);
local Player = PlayerService:GetPlayerFromCharacter(script.Parent.Occupant.Parent) -- get the player
print("got player")
if Player.Name == script.OwnerName.Value then -- check if its the owner
print("checked player name")
local dog = script.CarGui:Clone()
print("cloned gui")
dog.Parent = Player.PlayerGui
print("gave gui")
else -- if it isn't
script.Parent.Occupant.Jump = true -- make them jump
end
local PlayerService = game:GetService("Players") -- get playerservice
rat = false
script.Parent.GetPropertyChangedSignal("Occupant"):Connect(...);
local Player = PlayerService:GetPlayerFromCharacter(script.Parent.Occupant.Parent) -- get the player
print("got player")
if Player.Name == script.OwnerName.Value and Player.PlayerGui:findFirstChild("CarGui") == nil then -- check if its the owner
print("checked player name")
local dog = script.CarGui:Clone()
print("cloned gui")
dog.Parent = Player.PlayerGui
print("gave gui")
else -- if it isn't
script.Parent.Occupant.Jump = true -- make them jump
end
--game.Players for PlayerService?
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
local player = game.Players:FindFirstChild(script.Parent.Occupant.Parent.Name);
if player then
if player.Name == script.OwnerName.Value and not player.PlayerGui:findFirstChild("CarGui") then
local dog = script.CarGui:Clone();
dog.Parent = Player.PlayerGui;
else
script.Parent.Occupant.Jump = true;
end
end
end
--game.Players for PlayerService?
local function onParentChanged()
local player = game.Players:FindFirstChild(script.Parent.Occupant.Parent.Name);
if player then
if player.Name == script.OwnerName.Value and not player.PlayerGui:FindFirstChild("CarGui") then
local dog = script.CarGui:Clone()
dog.Parent = Player.PlayerGui
else
script.Parent.Occupant.Jump = true
end
end
end
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(onParentChanged)