Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleport with stats value = 5 Why it doesnt work?

Asked by 6 years ago
Edited 6 years ago

I want that when the player has an exact amount of "Objects" in leaderboard stats, he is teleported,im using that script,but it is not working,What is wrong?

Position=Vector3.new(-46.078, 5.046, -1105.82)
game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue", p)
stats.Name = "leaderstats"
local objects = Instance.new("IntValue", stats)
objects.Name = "Objects"
objects.Value = 0

while true do
wait (1)
if objects.Value = 5 then
FindFirstChild("Humanoid") then
Torso.CFrame=CFrame.new(Position)
    end
 end
 end
 end)

0
use code blocks please SulaymanArafat 230 — 6y
0
Done. SpringtraPlayer 16 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Ok so there are three main problems I see in your code. Number one: It is always better to use an event instead of a while loop. Instead of the while loop you should use the Changed event. Here is an example:

objects.Changed:Connect(function()

    if objects.Value == 5 then -- here is where your second problem occurs

        -- code here

    end

end)

When comparing objects to 5 you are forgetting to use ==. == is the way to compare to items. Not =, = is used to define things like tables and variables. Lastly, and this is not a major issue but it is important. On line three and five of your code you are using the second argument of Instance.new. That is deprecated and it can cause issues. If you want to read why, go here. I hope that this helps and have a great day scripting!

Ad

Answer this question