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

VIP Tp script prints out an error, and does not tp the player?

Asked by
awfulszn 394 Moderation Voter
6 years ago
Edited 6 years ago

I am attempting to make a VIP tp script, so that when a player with VIP touches the door, it will tp them to the position of the VIP room. Though this does not work, all it does is print out, 'Not a valid Player' on line 6.

Here is my script:

local gamepassId = 1109268370

function onTouch(hit)
    local player = hit.Parent
    local torso = player:FindFirstChild("Torso")
    if game:GetService("GamePassService"):PlayerHasPass(player, gamepassId) then
        torso.CFrame = CFrame.new(script.Parent.Parent.VIPPlatform.Position)
        wait()
    else
        return false
    end
end

script.Parent.Touched:Connect(onTouch)

Any help is appreciated, thanks.

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

When a player Touches something, it returns the character and not the player object. PlayerHasPass is looking for the player object, not a model in Workspace. :P

local gamepassId = 1109268370

function onTouch(hit)
    local character = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local torso = character:FindFirstChild("Torso") --EDIT: changed the variable used to character instead of player
    if game:GetService("GamePassService"):PlayerHasPass(player, gamepassId) then
        torso.CFrame = CFrame.new(script.Parent.Parent.VIPPlatform.Position)
        wait()
    else
        return false
    end
end

script.Parent.Touched:Connect(onTouch)

0
Oh, that worked perfectly! Thanks! awfulszn 394 — 6y
0
You're very welcome! :) BennyBoiOriginal 293 — 6y
Ad

Answer this question