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

Is my script right?

I just want new pair of eyes to check my scripting

function onButtonClicked()
local char = script.Parent.Parent.Parent.Parent.Parent.Parent.Character
X = (math.random(1,5))

if X == 1 then
char.Torso.CFrame = game.Workspace.Tele1.CFrame + Vector3.new(0, 10, 0) --tele1-5 is a brick in workspace

elseif X==2 then
char.Torso.CFrame = game.Workspace.Tele2.CFrame + Vector3.new(0, 10, 0)

elseif X==3 then
char.Torso.CFrame = game.Workspace.Tele3.CFrame + Vector3.new(0, 10, 0)

elseif X==4 then
char.Torso.CFrame = game.Workspace.Tele4.CFrame + Vector3.new(0, 10, 0)

elseif X==5 then
char.Torso.CFrame = game.Workspace.Tele5.CFrame + Vector3.new(0, 10, 0)
wait(0.25)
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

1 answer

✓ Accepted answer

You could cut this down in size quite a bit (and remove some of the repetitiveness).

local Player = game.Players.LocalPlayer --// Will only work in a LocalScript

script.Parent.MouseButton1Down:connect(function()
	local Character = Player.Character
	local X = math.random(5)
	if Character ~= nil and Character:FindFirstChild("Torso") then
		Character.Torso.CFrame = Workspace["Tele" .. X].CFrame + Vector3.new(0, 10, 0)
	end
end)

Though, to answer your original question, no your script wouldn't work. You're missing an end to close the function, though assuming you fixed this and also didn't muck up your parenting to their character, your script would work. Though, it would error if they didn't have a character or their torso was missing when they clicked the button.

1 comment

0

thanks

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