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

Serverside script printing wrong names, how to fix?

I am making a skill test script on my game which works by sending a server event request to a script in order to activate the skill, but I am having a very weird problem.

I tried to fix this several times but nothing worked, the problem is that when the serverside script is activated, it's supposed to print the name of the person that has casted the skill and then print the name of the target. But instead it prints the name of the caster twice, this problem doesn't happen on the local script and I have no idea why.

Local script:

--//Services
local players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

--//Variables
local remotes = repStorage:WaitForChild("Remotes")
local player = players.LocalPlayer
local mouse = player:GetMouse()

--//Skills
local soulReapRemote = remotes:WaitForChild("CastSkill_SoulReap")

--//Functions
local function onKeyPress(input, isTyping)
	if isTyping then return end
	if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	
	local mouseTarget = mouse.Target
	
	if input.KeyCode == Enum.KeyCode.G then
		if mouseTarget.Parent:FindFirstChild("Humanoid") then
			local caster = workspace:FindFirstChild(player.Name)
			local target = workspace:FindFirstChild(mouseTarget.Parent.Name)
			
                        print("Caster: ".. caster.Name..", Target: ".. target.Name..".")

			soulReapRemote:FireServer(caster, target)
		end
	end
end

--//Callers
UIS.InputBegan:Connect(onKeyPress)

Serverside script:

--//Services
local repStorage = game:GetService("ReplicatedStorage")

--//Variables
local remotes = repStorage:WaitForChild("Remotes")

--//Skills
local soulReapRemote = remotes:WaitForChild("CastSkill_SoulReap")

--//Functions
local function onSoulReapCast(wCaster, wTarget)
	print("Caster: ".. wCaster.Name..", Target: ".. wTarget.Name..".")
end

--//Callers
soulReapRemote.OnServerEvent:Connect(onSoulReapCast)

I'm sorry if this wasn't very understandable, I don't know how to describe it better, hope you understand!

1 answer

✓ Accepted answer

OnSercerEvent will give you player who FireServer. put more 1 variable for player.

local function onSoulReapCast(Player,wCaster, wTarget)

end

1 comment

0

It worked, thanks

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