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

GUI button to enable/disable trail effect in workspace?

[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

###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 

1 comment

0

See answer below

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

5 comments

0

Had to post it down here, so I could include my code, sorry for any inconvenience.

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.

0

^

0

Use ReplicatedStorage for client-server storage.

0

Ok, thank you both.

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