so i started scripting pretty recently but after i realized you cant connect to player in a server script i use playeradded but caused the script to stop working.
local part = script.Parent
local db = true
local function teleport(hit)
if not db then
db = true
local plr = hit.Parent
if game.Players:GetPlayerFromCharacter(plr) then
plr.LowerTorso.CFrame = game.Workspace.WaterWay.CFrame
end
wait(1)
db = false
end
end
game:GetService("Players").PlayerAdded:Connect(function(Player)
part.Touched:Connect(function(hit)
if Player.leaderstats.Rebirths.Value >= 5 then
teleport()
end
end)
end)
You have not passed the hit variable on to your teleport function. Your teleport function is being given nil as the argument for hit, even though the anon function for the part being touched has hit as an argument.
Add Print() to two of the functions, the one on PlayerAdded and the one of Teleport. Use them to find out which isnβt working. You could even add a Print() to when the player CFrame is about to change.
local part = script.Parent
local db = true
local function teleport(plr)
if not db then
local Character = plr.Character or plr.CharacterAdded:Wait()
db = true
local plr = hit.Parent
Character.HumanoidRootPart.CFrame = game.Workspace.WaterWay.CFrame
wait(1)
db = false
end
end
part.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild('Humanoid')
if Humanoid then
local PlayerFound = game.Players:GetPlayerFromCharacter(hit.Parent) --Aka Character
if not PlayerFound or PlayerFound.leaderstats.Rebirths.Value < 5 then return end --This will cancel the teleport of the conditions are NOT met.
teleport(PlayerFound)
end
end)