Teleport script

How do i make that when player teleport his stage stats return to 1.
the teleport is working but the stage value not changing .

script:

local Pad2 = game.Workspace.Teleport3
local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(touchPart, player)
	if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
		local Character = touchPart.Parent
		local teleportLocation = CFrame.new(Pad2.CFrame.X, Pad2.CFrame.Y + 5, Pad2.CFrame.Z)
		Character:SetPrimaryPartCFrame(teleportLocation)
		player.leaderstats.Stage.Value = 1
		local teleportingValue = Character.currentlyTeleporting
		teleportingValue.Value = true
		wait(3)
		teleportingValue.Value = false
	end
end)

this part is not working: player.leaderstats.Stage.Value = 1

2 Likes

I’m not entirely sure that player is identified with a touch…

Perhaps do this instead:

local player = game:GetService("Players"):GetPlayerFromCharacter(Character) -- You already identified the Character. (touchPart.Parent)
    if (player) then
        -- do stuff/player.leaderstats.Stage.Value = 1
    end

I hope this is helpful!

You can also see in Youtube if you want to learn how to script :grinning_face_with_smiling_eyes:

1 Like

where do i put this script? i need to replace it with my script?

local Pad2 = game.Workspace.Teleport3
local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(touchPart)
	if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
		local Character = touchPart.Parent
        local player = game:GetService("Players"):GetPlayerFromCharacter(Character) -- You already identified the Character. (touchPart.Parent)

		local teleportLocation = CFrame.new(Pad2.CFrame.X, Pad2.CFrame.Y + 5, Pad2.CFrame.Z)
		Character:SetPrimaryPartCFrame(teleportLocation)
		
        if (player) then
        -- do stuff/player.leaderstats.Stage.Value = 1
        end

		local teleportingValue = Character.currentlyTeleporting
		teleportingValue.Value = true
		wait(3)
		teleportingValue.Value = false
	end
end)

Like this is fine, just add the variables and clean up a bit so you’re not lost.

1 Like

If you want to get the player you must use game.Players:GetPlayerFromCharacter.() The second argument is nil in your script.

1 Like