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

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

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

✓ Accepted answer

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)

2 comments

0

Oh, that worked perfectly! Thanks!

0

You're very welcome! :)

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