so i wanna make when player sit, they get money which is repeated
And what is the issue you’re having with it?
You are reading the seated event of humanoid or reading a seat changed signal event?
local Seat = script.Parent
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant ~= nil then
warn("give money")
end
end)
my issue is that whenever i tried to repeat it it just wont stop when i get up
show your code, probably something still connected, maybe you should read when player left the seat to stop that money giving function
script.Parent.ChildAdded:connect(function(child)
if child.Name == "SeatWeld" then
local human = child.part1.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
print('player is here',human)
-- Now insert your script below
while wait(2) do
print("hello")
end
end
end
end)
(i took it out of toolbox but the repeat thing is my self)
When a player sit on that part, the script is cheking if a SeatWeld is added, then finding the Humanoid of the player, then creating a while loop repeating each 2 seconds, printing hello.
That loop will remain forever if you dont break it.
I suggest using this script instead of that one, its reading the Occupant, not the welds, and stoping the loop when player leaves the seat:
local Seat = script.Parent
local SeatedPlayer
local function MoneyLoop()
while SeatedPlayer do
warn("giving money to", SeatedPlayer)
wait(2)
end
end
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant ~= nil then
SeatedPlayer = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
warn("a player is sit:", SeatedPlayer)
MoneyLoop()
else
warn(SeatedPlayer, "left seat")
SeatedPlayer = Seat.Occupant
end
end)
oh i see, thank you. i also dont understand the weld thingy cause its just from toolbox so yea
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.