Do LocalScripts work in the Workspace?


Question

Are you able to use the print() or warn() commands on a local script?

Why I’m asking

I’m asking because I’m currently attempting to make a chant system and I have everything sound related working on the client for multiple reasons.

The issue

My issue is that everytime I copy the localscript into the audio to run the following code and it isn’t working at all. I have no way to detect if there is an issue with the coding. I’ve done my best to decode it through the server-side, the script is perfectly fine; so I have no idea why it’s not working on the client side, and seeing as the audio is being controlled on the client side; it genuinely makes no sense.

The Idea

  1. A Chat command is said, (i.e; Bell Ring)
  2. The audio is created and put in a folder on the Server,
  3. A remote event is created and is fired to all the clients,
  4. The Client Script then goes through the Workspace to find the said Audio and plays it.
  5. Its Volume then rises by increments. The highest volume being whatever you send through the remote event and the lowest being 0.

This is where the issue comes into action.

  1. The LocalScript below is then duplicated into the Sound,
  2. The sounds volume is supposed to lower all the way down to 0 and then the script disables itself.

That’s it

Side Note

The reason I can’t use a server script for this is because the actual sound isn’t played through the server, for many different reasons revolving around the Client and Server Connection that I won’t get into.

The Local Script

wait(5)
while script.Disabled == false do
	local Audio = script.Parent
	if Audio.Volume > 0 then
		Audio.Volume = Audio.Volume - .005
		wait(.01)
	else
		script.Disabled = true
	end
end

Thank you for any info you can give me.

1 Like

Local scripts will not execute if they are parented to the wrong directory.

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service
18 Likes

Just a question, when you equip tool, the tool goes in workspace.PlayerCharacter, the local scripts inside it runs, how is that possible, its in workspace

Local scripts work inside the character model (even though the character model is inside the workspace), consider it an exception to the general rule.

Because of Network ownership, if you have network ownership over a model or part, you will be able to control the part/model with local scripts and those action will replicate to the server, a player’s character network ownership is instantly given to said player once it spawns and thus allows local scripts inside of it to work. This networking behavior also explains why exploiters have complete control over their own character. Network ownership can only be set from the server.

1 Like

Apologies for bumping, but I figured this is an important update to mention considering this is the top results on Google when searching for “Local Scripts in Workspace”.

The new Script instance now allows you to choose a RunContext. It was in Beta for while but is now Live. If you choose Client as the RunContext, you essentially have a local script, but it will run pretty much anywhere, including in the workspace.

For extra reading, here are a few links:
Run Context Announcement (Most Useful)
Official Documentation (Not too useful, but I’ll still include it)

Just thought I’d mention this for any newer developers wondering about this.

Cheers,
Aston.

20 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.