Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Teleport with stats value = 5 Why it doesnt work?

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)

2 comments

0

use code blocks please

0

Done.

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.