Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is my script right?

Asked by 10 years ago

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

Log in to vote
1
Answered by
DataStore 530 Moderation Voter
10 years ago

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.

0
thanks awesomegamers200 72 — 10y
Ad

Answer this question