Script not working

I have a GUI that charges a player and it teleports them but I want to make it so that they can touch a part only after they paid and get teleported since they paid. I have a script for this inside a part, but it won’t work.
Script:

local VipDoor = workspace:WaitForChild("Barrier")
local player = script:FindFirstAncestorWhichIsA("Player")

if player.PlayerGui.ActivityGui.Frame.Shell.TextButton.Text == "Paid" then
	VipDoor.Touched:Connect(function(h)
		local hum = h.Parent:FindFirstChild("Humanoid")
		if hum ~= nil then
			h.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace["Teleport"].Position)
			player.PlayerGui.ActivityGui.Enabled = false
		end
	end)
end

Is this a local script and is it inside of workspace?

Try chaging the Player pos with h.Parent:SetPrimaryPartCFrame(workspace[“Teleport”].CFrame)

change it to a localscript if it’s a serverscript

I changed it to a local script and used local player but it didnt work (I have other scripts without the checking the text and they’re not local scripts and they work just fine

Hi there, what errors (if any) do you receive?

Hi I don’t see any errors in my output im just hitting my union instead of teleporting

The if statement will only run once so you should put it inside the VipDoor.Touched function. Also wouldn’t recommend using Text to check this since players can easily change this.

you also cannot find the localplayer in a serverscript. Use a localscript for this…

1 Like

I used a local script inside the part and this script but it still didnt work:

local VipDoor = workspace:WaitForChild("Barrier")
local player = game.Players.LocalPlayer

VipDoor.Touched:Connect(function(h)
	if player.PlayerGui.ActivityGui.Frame.Shell.TextButton.Text == "Paid" then
		local hum = h.Parent:FindFirstChild("Humanoid")
		if hum ~= nil then
			h.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace["Teleport"].Position)
			player.PlayerGui.ActivityGui.Enabled = false
		end
	end
end)

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service
4 Likes

I forget this a-lot and it always takes me a while before I can notice. :slight_smile:

1 Like

I made it a regular script but I don’t know how I would get the player

get the player using game:GetService(“Players”):GetPlayerFromCharacter.

in this case you would do

if hum~=nil then
local player = players:GetPlayerFromCharacter(h.Parent)
1 Like

you could also use a remote event to fire to the client from the server and then turn off playergui on the client. I’m not sure if the server can access playergui.

local player = players:GetPlayerFromCharacter(hit.Parent)
remote:FireClient(player)
remote.OnClientEvent:Connect(function()
game.Players.LocalPlayer.PlayerGui.GuiObject.Enabled = false
end)

I think I’m going to make a local script inside the button with the text make a script inside the part enable if you bought the thing and have it disabled by default and just use the script that ik works to teleport you

I made the purchase the entry button script make the teleport script inside the part enable but it doesn’t work
here’s the script

local player = game.Players.LocalPlayer
local door = game.Workspace.Barrier

script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.Shells.Value >= 25 then
		-- Checks if player has enough shells
		game.Workspace.PurchaseSuccessful:Play()
		game.ReplicatedStorage.Enter:FireServer(25)
		-- Fires RemoteEvent that charges player
		script.Parent.Text = ("Paid")
		script.Disabled = true
		script.Parent.Parent.Parent.Parent.Enabled = false
		player.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Teleport.Position)
		wait()
		door.Entry.Disabled = false
	else
		game.Workspace.PurchaseFailed:Play()
		script.Parent.Text = ("Insufficient funds!")
		wait(3)
		script.Parent.Text = ("Enter for 25 Shells...")
		end
	end)

Ok I solved this by setting the barrier position when you purchase the thing so that it only works that way