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

Changing local script to server script?

Asked by 4 years ago

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!

0
What are you trying to accomplish? Dovydas1118 1495 — 4y
0
I am trying to make a gunshot sound, but i dont know how to do it server sided. Johannes_11 1 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)
0
Yes i am. Johannes_11 1 — 4y
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. SteamG00B 1633 — 4y
Ad

Answer this question