What's wrong with this script?

Basically, a door that you need money to use, and it teleports you if you have enough money

local limit = 1000

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.leaderstats.Coins.Value >= limit then
				hit.Parent.Head.CFrame = CFrame.new(workspace.TeleportPart.Position + Vector3.new(0,3,0))
			end
		end
	end
end)

Try setting the characters HumanoidRootPart.CFrame instead of the Head. Are you getting any errors? Or is it just not performing the teleport?

1 Like

No errors in the output, the player is not getting teleported

Edit: Nevermind

Workspace.Door.Script:11: Expected ‘)’ (to close ‘(’ at line 3), got ‘end’

local limit = 1000

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.leaderstats.Coins.Value >= limit then
			hit.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace.TeleportPart.Position + Vector3.new(0,3,0))
		end
	end
end)

You had an extra end.

1 Like

Just went to test it out, it’s still not teleporting

Something you should always try when your script doesn’t work is to put a lot of: print(“…”) at pretty much every lines, that way, you can see if you’re script doesn’t work/what’s happening. For example, if now you put tons of print(“…”) and they’re all showing up, it would means that your script is working, but you’re just setting something the wrong way, for example, not getting the good part of the player to teleport.

I’m not 100% sure, but you should try this:

hit.Parent.CFrame = CFrame.new(workspace.TeleportPart.Position + Vector3.new(0,3,0))

2 Likes