Fire Events From Client To Server

So I got 2 scripts the first is a local script and the other one a server script
First One:

local tool = script.Parent
local Player = game.Players.LocalPlayer -- Getting the player
local char = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse() -- Getting the players mouse]
local RS = game:GetService("ReplicatedStorage")
local MakimaEvent = RS.Events:WaitForChild("Makima")




	Mouse.Button1Down:Connect(function() -- Detecting when the player presses the left mouse button
	if tool.Parent == char then
		local clickchar = Mouse.Target.Parent
		if clickchar:FindFirstChild("Humanoid") then -- Checking if the Mouse is over a player
			local dist = (char.HumanoidRootPart.Position - clickchar.HumanoidRootPart.Position).Magnitude
			if dist <= 30 then
				print(Mouse.Target.Parent.Name)
				local enemy = Mouse.Target.Parent
				MakimaEvent:FireServer(enemy)
			end
		end

	end
	end)

Second One:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RS = game:GetService("ReplicatedStorage")

local MakimaEvent = RS.Events:WaitForChild("Makima")

local VFX = RS:WaitForChild("VFX")

local Blood = VFX:WaitForChild("Blood")

local function onMakimaFired(enemy)

local NewBlood = Blood:Clone()

NewBlood.Parent = workspace

NewBlood.Position = enemy:WaitForChild("Torso")

end

MakimaEvent.OnServerEvent:Connect(onMakimaFired)

So I am trying to pass the enemy to the server but this doesnt really work because it gives me the player and not the person who I clicked on for some reason.
Can someone help me?

1 Like

When firing to the server you need to make sure the function is formatted like this

function onMakimaFired(Player, enemy) 

end)

When you fire a client event to the server it sends a secret parameter along “The Player”.
So when the server receives the event it should have one parameter for the Player and all the other parameters can then be placed that you send over.

tysm this really helped me out.

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