RemoteEvent not affecting the player who ran it?

So I’ve been trying to make a sword using OOP, just to test my abilities after a long time of not doing anything in Roblox Studio. But ended up taking it seriously, and trying to make a game around it. The issue is that, once I was testing with friends, I noticed only one player spawned with the sword in their character.

And let’s say you equip the weapon with the key “E”, the player who had the sword could equip it, but if other players that didn’t spawn with the sword pressed the key, the player who actually has the sword would equip it. It’s something that has happened to me before, some players can control what other players do. I believe I can fix this by checking if the player that fired the RemoteEvent is the same as the local player, but I still wanna ask here to make sure this is the best solution I have, and if could, actually be told what’s the reason behind this weird problem.

(I cannot prove the code, because I deleted it all and restarted all over again, so I lost it.)

Hope you can help me :grinning:

1 Like

Hi! I can help you, but I need code to see what you do wrong. Could you please remake it and send it here? (If you are able to send it, would you add some text saying if it is a local script or not? Thank you!)

I actually checked through my autosaves and found the old code.

Local script

--|| SERVICES ||--
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--|| VARIABLES ||--
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Weapon = require(game.ReplicatedStorage.Modules.Weapon)
local CanEquip = true

--|| Events ||--
local Event = ReplicatedStorage.Remotes.WeaponEvents.Event

--|| Script ||--
UserInputService.InputBegan:Connect(function(hit, chat)
	if chat then return end
	if hit.KeyCode == Enum.KeyCode.E and CanEquip == true then
		Event:FireServer("Equip")
		CanEquip = false
		task.wait(0.45)
		CanEquip = true
	end
end)

Server Script

--|| SERVICES ||--
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--|| VARIABLES ||--
local Weapon = require(ReplicatedStorage.Modules.Weapon)

--|| Events ||--
local WeaponEvent = game.ReplicatedStorage.Remotes.WeaponEvents.Event

WeaponEvent.OnServerEvent:Connect(function(Player, String)
	local Character = Player.Character
	
	if String == "Equip" then
		Weapon:Equip(Character)
	end
end)

Module Script

--// Services
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Class = require(game.ReplicatedStorage.Modules.Class)

--// Util
local Remotes = ReplicatedStorage.Remotes
local Assets = ReplicatedStorage.Assets

--// Class
local Weapon = Class:extend()

--// Class' Properties
function Weapon:new(Weapon, Owner)
	local Module = require(script[Weapon])
	local Settings = Module.Settings

	self.Owner = Owner or nil
	self.Name = Settings["Name"] or "Katana"
	self.Damage = Settings["Damage"] or 0.2
	self.Knockback = Settings["Knockback"]  or 20
	self.AttackSpeed = Settings["AttackSpeed"] or 0.3
	
	self.CanAttack = false
	self.Equipped = false
	
	Module.CreateModel(Owner)
end

function Weapon:Equip(Owner)
	local Humanoid = Owner:FindFirstChild("Humanoid")
	
	if Humanoid:GetAttribute("State") == "None" then
		Owner.Humanoid:SetAttribute("State", "Armed")
		
		Owner.Sheath.Effect.Attachment.Emitter:Emit(1)
		Owner.Sheath.Effect.Attachment.Emitter2:Emit(1)
		
		Owner.Torso:FindFirstChild("UnequippedWeld").Enabled = false
		Owner["Right Arm"]:FindFirstChild("EquippedWeld").Enabled = true
		
		self.CanAttack = true
		self.Equipped = true
	elseif Humanoid:GetAttribute("State") == "Armed" then
		Owner.Humanoid:SetAttribute("State", "None")

		Owner.Torso:FindFirstChild("UnequippedWeld").Enabled = true
		Owner["Right Arm"]:FindFirstChild("EquippedWeld").Enabled = false
		
		self.CanAttack = false
		self.Equipped = false
	end
end

return Weapon

I apologize if a lot of things don’t make sense, or arent efficient. It was my first time doing anything with Object Oriented Programming