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

GUI button to enable/disable trail effect in workspace?

Asked by
MexheCo 46
6 years ago
Edited 6 years ago

[Edited with my code]

Hello,

I want to make a button that will disable/enable a trail in the workspace through StarterGUI.

I have the button already made, and here is the code I have:

local trail = workspace.RainbowTrail.Trail

function OnButtonClick()

    if trail.Enabled == false then
        trail.Enabled = true
    end

     if trail.Enabled == true then
        trail.Enabled = false
end 

end

The trail is a child of a script (I got the trail from the toolbox), and is in the workspace.

Any help is welcome!

Thanks in advance, MexheCo

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Seems like you didn't connect it to an event. Make sure this is a LocalScript and under your button.

-- LocalScript, under your button

local trail = game.Workspace.RainbowTrail.Trail

function OnButtonClick()
    trail.Enabled = not trail.Enabled
    -- Save some lines of code! Simple way to toggle a boolean. 
end

script.Parent.MouseButton1Click:Connect(OnButtonClick)
-- event listens for the gui being clicked 
0
**See answer below** MexheCo 46 — 6y
Ad
Log in to vote
0
Answered by
MexheCo 46
6 years ago

Thanks for the help. It's still not working though, probably user error on my part :P

I changed my "Script" to "LocalScript" and pasted your code in.

I also changed the location of the "RainbowTrail" script (which was in Workspace) into ServerScriptService.

Now I have this:

local trail = game.ServerScriptService.RainbowTrail.Trail

function OnButtonClick()
    trail.Enabled = not trail.Enabled

end

script.Parent.MouseButton1Click:Connect(OnButtonClick)

Any reason why this wouldn't be working?

Thanks again, MexheCo

0
Had to post it down here, so I could include my code, sorry for any inconvenience. MexheCo 46 — 6y
0
ServerScriptService is not seen by the client/local scripts. Your "Trail" should be in workspace in order to be seen. Any new problems should also be posted as a new question because this is reserved for answers only. xPolarium 1388 — 6y
0
^ User#19524 175 — 6y
0
Use ReplicatedStorage for client-server storage. User#19524 175 — 6y
0
Ok, thank you both. MexheCo 46 — 6y

Answer this question