How would I make this script work serverside?

  1. What I want to do here.
    Trying to make something close to the Deep Rock Galactic flare system.

  2. Why don’t i just fix it myself?
    Can’t seem to get the script to work on the serverside.

  3. What I’ve tried.
    I’ve tried to use RemoteEvents, but I’m just not that good with using them.

I’m aware the script is a mess, no need to point it out.

local Flare = game.ReplicatedStorage.Equipment.Flare
local Mouse = game.Players.LocalPlayer:GetMouse()
local Player = game.Players.LocalPlayer
local Attachment = Instance.new("Attachment", Flare)
local HRP = Player.Character.HumanoidRootPart
local myDebounce = true
repeat
	wait()
until Player.Character
Mouser = Player:GetMouse()
name = Player.Name
char = game.Workspace[Player.Name]

Mouser.KeyDown:connect(function(key)
	if key == "f" then
		local Clone = Flare:Clone()
		if myDebounce == true then
			myDebounce = false
		Clone.Parent = game.Workspace
		Clone.Position = HRP.CFrame * Vector3.new(0,0,-3)
		local direction = Mouse.Hit.LookVector 
		local forceMultipliter = 30
			Clone:ApplyImpulse(direction * forceMultipliter)
			wait(6)
			myDebounce = true
			wait(20)
			Clone:Destroy()
		end
		end
end)

This is the part that needs to go on the server:

if myDebounce == true then
			myDebounce = false
		Clone.Parent = game.Workspace
		Clone.Position = HRP.CFrame * Vector3.new(0,0,-3)
		local direction = Mouse.Hit.LookVector 
		local forceMultipliter = 30
			Clone:ApplyImpulse(direction * forceMultipliter)
			wait(6)
			myDebounce = true
			wait(20)
			Clone:Destroy()
		end

When you fire a remote event, it just triggers an event on the server, exactly how a KeyDown event works, except you can pass extra arguments. The signature of FireServer is:
FireServer(...)

The . . . means any number of extra arguments, which will be unpacked at the event handler:

myRemoteEvent.OnServerEvent:Connect(function(arg1, arg2)
--Put server code here
end)

You should one argument to pass the HRP.CFrame. Your remote event object just needs to be in a location visible to both the client and server, such as the workspace or ReplicatedStorage.

Not sure if I put it in right, most likely not.

Here’s the local script

local Flare = game.ReplicatedStorage.Equipment.Flare
local Mouse = game.Players.LocalPlayer:GetMouse()
local Player = game.Players.LocalPlayer
local Attachment = Instance.new("Attachment", Flare)
local HRP = Player.Character.HumanoidRootPart
local myDebounce = true
local myRemoteEvent = game.ReplicatedStorage.ExampleForTheFlaresOrSomething
repeat
	wait()
until Player.Character
Mouser = Player:GetMouse()
name = Player.Name
char = game.Workspace[Player.Name]

Mouser.KeyDown:connect(function(key)
	if key == "f" then
		local Clone = Flare:Clone()
		Clone.Name = "Clone"
		myRemoteEvent:FireServer(HRP.CFrame)
		end
end)

And the server script.

local myRemoteEvent = game.ReplicatedStorage.ExampleForTheFlaresOrSomething

myRemoteEvent.OnServerEvent:Connect(function(CFrame)

if myDebounce == true then
	myDebounce = false
	Clone.Parent = game.Workspace
	Clone.Position = HRP.CFrame * Vector3.new(0,0,-3)
	local direction = Mouse.Hit.LookVector 
	local forceMultipliter = 30
	Clone:ApplyImpulse(direction * forceMultipliter)
	wait(6)
	myDebounce = true
	wait(20)
	Clone:Destroy()
	end
	end)

I’m probably missing something here that should be easy to understand, sorry bout that.

You correctly pass the HRP CFrame but you need to do all the steps of cloning the flare and placing it, giving it velocity on the server.

I’m not sure I know what you mean, but I’ve done what I got from this.

local myRemoteEvent = game.ReplicatedStorage.ExampleForTheFlaresOrSomething
local Flare = game.ReplicatedStorage.Equipment.Flare
local myDebounce = true
myRemoteEvent.OnServerEvent:Connect(function(CFrame)

if myDebounce == true then
	myDebounce = false
	local Clone = Flare:Clone()
	Clone.Name = "Clone"
	Clone.Parent = game.Workspace
	Clone.Position = HRP.CFrame * Vector3.new(0,0,-3)
	local direction = Mouse.Hit.LookVector 
	local forceMultipliter = 30
	Clone:ApplyImpulse(direction * forceMultipliter)
	wait(6)
	myDebounce = true
	wait(20)
	Clone:Destroy()
	end
	end)

local myRemoteEvent = game.ReplicatedStorage.ExampleForTheFlaresOrSomething
local Flare = game.ReplicatedStorage.Equipment.Flare
local myDebounce = true

myRemoteEvent.OnServerEvent:Connect(function(hrpCFrame)
	if myDebounce == true then
		myDebounce = false
		local Clone = Flare:Clone()
		Clone.Name = "Clone"
		Clone.Parent = game.Workspace
		Clone.Position = hrpCFrame * Vector3.new(0,0,-3)
		local direction = hrpCFrame:VectorToWorldSpace(-Vector3.zAxis)
		local forceMultipliter = 30
		Clone:ApplyImpulse(direction * forceMultipliter)
		wait(6)
		myDebounce = true
		wait(20)
		Clone:Destroy()
	end
end)

I put this into the server script, Didn’t work but it is still triggering the script

What does it mean if it didn’t work?

Only thing that didn’t work is the flare, it didn’t create one.

local myRemoteEvent = game.ReplicatedStorage.ExampleForTheFlaresOrSomething
local Flare = game.ReplicatedStorage.Equipment.Flare
local myDebounce = true

myRemoteEvent.OnServerEvent:Connect(function(plr,hrpCFrame)
	if myDebounce == true then
		myDebounce = false
		local Clone = Flare:Clone()
		Clone.Name = "Clone"
		Clone.Parent = game.Workspace
		Clone.Position = hrpCFrame * Vector3.new(0,0,-3)
		local direction = hrpCFrame:VectorToWorldSpace(-Vector3.zAxis)
		local forceMultipliter = 30
		Clone:ApplyImpulse(direction * forceMultipliter)
		wait(6)
		myDebounce = true
		wait(20)
		Clone:Destroy()
	end
end)

You forgot that the player is always passed as the first argument :wink:

2 Likes

Thank you, didn’t realise that.

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