Hi guys, I am trying to make a script that teleports you if you have 1 win or more. I tried a bunch of combinations but none of them seemed to have worked. I tried using a RemoteEvent etc… Here is what I’ve come up with so far:
script.Parent.Touched:Connect(function(player, h)
local hum = h.Parent:FindFirstChild("Humanoid")
if hum ~= nil and player.leaderstats.Wins <= 0 then
h.Parent.HumanoidRootPart.CFrame = CFrame.new(-51, 83.5, -154)
end
end)
the player is not a parameter in a touched event, so I would get rid of that first variable. Only the object that has touched the script’s parent will be the parameter. if you were to try and check the player’s Wins value you would have to use the GetPlayerFromCharacter() function.
if hum then
local player = game.Players:GetPlayerFromCharacter(h.Parent)
if player then -- checks to see if they are a real player
-- your code here
end
end
script.Parent.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(h.Parent)
if hum ~= nil and player.leaderstats.Wins <= 0 then
h.Parent.HumanoidRootPart.CFrame = CFrame.new(-51, 83.5, -154)
end
end)
Nevermind now it says there is an error on Line 4: [Workspace.WinnersTeleport.TeleportPart.WinnersDoor:4: attempt to compare userdata and number]
I think this is coz u tried to find humanoid before it loaded in, maybe try changing line 2 to
local hum = h.Parent:WaitForChild(“Humanoid”)
try adding a .Value behind wins
script.Parent.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(h.Parent)
if hum ~= nil and player.leaderstats.Wins.Value <= 0 then
h.Parent.HumanoidRootPart.CFrame = CFrame.new(-51, 83.5, -154)
end
end)
local rp = game:GetService("ReplicatedStorage")
local debounce = false
workspace.YOURTELEPORTER.Touched:Connect(function()
if debounce == false then
debounce = true
rp.YOURREMOTE:FireServer()
wait(5)
debounce = false
end
end
server script
local rp = game:GetService("ReplicatedStorage")
rp.YOURREMOTE.OnServerEvent:Connect(function(player)
if player.leaderstats.Wins.Value <0 then
player.Character.HumanoidRootPart.CFrame = CFrame.new(-51, 83.5, -154)
end
end
not much else to say, pretty easy.
also sorry if the spacing is bad, just made it here on devforum
you replace YOURREMOTE and YOURTELEPORTER?
also make sure if any symbols are incorrect, i know some devforum symbols are different than roblox studio symbols, just as “”
improper end structure, here is updated server code
local rp = game:GetService("ReplicatedStorage")
rp.YOURREMOTE.OnServerEvent:Connect(function(player)
if player.leaderstats.Wins.Value <0 then
player.Character.HumanoidRootPart.CFrame = CFrame.new(-51, 83.5, -154)
end
end)