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

How to teleport a player on touches? [SOLVED]

Asked by 8 years ago

hey, i made a teleport brick when player touches they get teleport and get a leaderstats. But its not working whats wrong?

Error: Script', Line 24

local ting = 0

function onTouched(hit)
    if ting == 0 then
    ting = 1
    check = hit.Parent:FindFirstChild("Humanoid")
    v=hit.Parent:FindFirstChild("Torso")

    if check ~= nil then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = user:findFirstChild("leaderstats")

        if stats ~= nil then
            local TWEE = stats:findFirstChild("Exp")
            local VIER = stats:findFirstChild("Wins")
            local ZEVEN = stats:findFirstChild("Coins")

                TWEE.Value = TWEE.Value + 10
                VIER.Value = VIER.Value + 1
                ZEVEN.Value = ZEVEN.Value + 2
        end
        if (v~=nil) then 
        v.Character.Torso.CFrame = CFrame.new(Vector3.new(-37.161, 43.18, 72.114))
        else print("No Teleport")
        end
    end

    ting = 0
    end
end

script.Parent.Touched:connect(onTouched)

3 answers

Log in to vote
1
Answered by
rexbit 707 Moderation Voter
8 years ago

Line 24 is a misconception because v( line 7) is the Torso already.

local ting = 0

function onTouched(hit)
    if ting == 0 then
    ting = 1
    check = hit.Parent:FindFirstChild("Humanoid")
    v=hit.Parent:FindFirstChild("Torso")

    if check ~= nil then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = user:findFirstChild("leaderstats")

        if stats ~= nil then
            local TWEE = stats:findFirstChild("Exp")
            local VIER = stats:findFirstChild("Wins")
            local ZEVEN = stats:findFirstChild("Coins")

                TWEE.Value = TWEE.Value + 10
                VIER.Value = VIER.Value + 1
                ZEVEN.Value = ZEVEN.Value + 2
        end
        if (v~=nil) then 
        v.CFrame = CFrame.new(-37.161, 43.18, 72.114)
        else print("No Teleport")
        end
    end

    ting = 0
    end
end

script.Parent.Touched:connect(onTouched)
0
God, I see i have an other problem. When player touches you get teleport but get double the values. So everything twice sometimes even 3 times does someone know how to fix that? minetrackmania 186 — 8y
Ad
Log in to vote
1
Answered by
Chronomad 180
8 years ago

I think I see your problem. On line 7 you have,

 v=hit.Parent:FindFirstChild("Torso")

Which makes v represent the players torso.

At line 24 you're basically saying

Torso.Character,Torso.CFrame = CFrame.new(-37.161, 43.18, 72.114)

Changing line 24 to

v.CFrame = CFrame.new(-37.161, 43.18, 72.114)

should do the trick.

Let me know if this helps at all!

Log in to vote
-2
Answered by 8 years ago

Simple. When doing CFrame you do not have to use Vector3. Just remove it.

local ting = 0

function onTouched(hit)
    if ting == 0 then
    ting = 1
    check = hit.Parent:FindFirstChild("Humanoid")
    v=hit.Parent:FindFirstChild("Torso")

    if check ~= nil then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = user:findFirstChild("leaderstats")

        if stats ~= nil then
            local TWEE = stats:findFirstChild("Exp")
            local VIER = stats:findFirstChild("Wins")
            local ZEVEN = stats:findFirstChild("Coins")

                TWEE.Value = TWEE.Value + 10
                VIER.Value = VIER.Value + 1
                ZEVEN.Value = ZEVEN.Value + 2
        end
        if (v~=nil) then 
        v.Character.Torso.CFrame = CFrame.new(-37.161, 43.18, 72.114) --Fixed
        else print("No Teleport")
        end
    end

    ting = 0
    end
end

script.Parent.Touched:connect(onTouched)

0
Uhmm still doesn't work.. still line 24 minetrackmania 186 — 8y

Answer this question