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

Changing local script to server script?

I'm trying to change this local script to a server script. Can someone please help? This is the script:

local Player = script.Parent.Parent
local Mouse = Player:GetMouse()
 
Mouse.Button1Down:connect(function()
	Player.Character.Torso.Fire:Play()
end)

Thanks!

2 comments

0

What are you trying to accomplish?

0

I am trying to make a gunshot sound, but i dont know how to do it server sided.

1 answer

✓ Accepted answer

Remote Events. Remote Events allow the server and the client to communicate with each other. Make sure you put the Remote Event in ReplicatedStorage.

Local Script

local Player = script.Parent.Parent
local Mouse = Player:GetMouse()
local remoteEvent = game.ReplicatedStorage.RemoteEvent

Mouse.Button1Down:Connect(function() --Capitalise the Connect, as connect is deprecated.
	remoteEvent:FireServer() --We won't need any parameters except the player.
end)

Server Script

local remoteEvent = game.ReplicatedStorage.RemoteEvent

remoteEvent.OnServerEvent:Connect(function(player) --This is what we need.
	player.Character.Torso.Fire:Play() --I'm assuming you're using R6.
end)

2 comments

0

Yes i am.

0

This is actually not a good idea for sounds, what you should do is modify the character sound system to include the ability to handle gunshots and other sounds.

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