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

Need help ASAP script keeps glitching/not working why? (Read desc)

I tried to do is when a player touches the brick he/she won't be able to teleport I tried making the script but, sadly fail can anyone help me please thanks!

local db = true
local player = game.Players.LocalPlayer
local target = game.Workspace.TeleportPart
local delay = 3
script.Parent.MouseButton1Click:connect(function()
	if db == true then
		db = false
		player.Character.HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0, 3, 0)
		for i = delay, 1, -1 do
			script.Parent.Text = i
			wait(4)
		end
		script.Parent.Text = "Teleport to Red Brick"
		db = true
	end
end)

1 answer

Revised Local Script under TextButton

local db = true
local player = game.Players.LocalPlayer
local target = workspace.TeleportPart
local textbutton = script.Parent

textbutton.Activated:Connect(function()
	if db == true then
		db = false
		player.Character:SetPrimaryPartCFrame(target.CFrame * CFrame.new(0, 3, 0))
		for i = 3, 1, -1 do
			textbutton.Text = i
			wait(4)
		end
		textbutton.Text = "Teleport to Red Brick"
		db = true
	end
end)

A. game.Workspace can be simplified into workspace

B. Use Activated instead of MouseButton1Click since Activated works for all devices, while MouseButton1Click only works for computers

C. delay is an actual function, but since you only use it as a variable once, you can just remove this and place the number into the for-loop

D. Use :SetPrimaryPartCFrame() to be sure that you move the whole character, since the player character is a model, and otherwise you may only move the HumanoidRootPart and not the rest of the player.

7 comments

0

Do I put this in a brick?

0

?

0

The whole experience of programming is called trying things out yourself.

0

@johnneedhelp ignore the guy above me, put it in the text button

0

The idea of having a variable is to help with maintainability and this is just the same code? -_-

0

@domnioplayer6 sorry for the late respond it was late at night and I fell alsleep.

0

@john, this should be a local script placed into a text button under a screen gui in startergui, then it should work

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