Hey developers, I’m trying to make a system where if a player sits on a VehicleSeat then they are given a tool, but the it isn’t giving them the tool, please help!
Script;
local Player
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local Char = seat.Occupant
Player = game.Players:GetPlayerFromCharacter(Char)
print("New player")
end)
while true do
if Player then
local FindTool = Player.Backpack:FindFirstChildWhichIsA("Tool")
if FindTool and FindTool.Name == "Paddle" then
print("having tool")
if FindTool.Equipped == true then
UsingTool = true
print("using tool")
else
UsingTool = false
print("not using tool")
end
else
game.ServerStorage.Paddle:Clone().Parent = Player.Backpack
print("not having tool")
end
end
task.wait()
end
local Player
function Occupant()
local Char = seat.Occupant
plr = game.Players:GetPlayerFromCharacter(Char)
if plr then
print("New player")
return game.Players:GetPlayerFromCharacter(Char)
end
end
Player = Occupant()
seat:GetPropertyChangedSignal("Occupant"):Connect(Occupant)
-- Rest of the Code
I got this Example by testing this:
local Player -- Misleading Variable
function A()
local i = 20
if i == 20 then
return 20 + 1 -- 21
end
end
Player = A()
print(Player) -- Prints "21" due to the function returning it
This Should transfer the data to the Variable so it isnt lost
I am dumb tho so i may be wrong