the remote event suppose to find a instance with the weapon tag and make it the weapon variable value, but when another fire the remote function it will assign the other player weapon to the variable, and all of the script is ran on their weapon. Trying to find a way around this its a script in Stater character script
local char = script.Parent
local weapon
RemoteEvent.OnServerEvent:Connect(function(plr, input, stamina)
for i, v in pairs(plr.Character:GetChildren()) do
if CollectionService:HasTag(v ,"weapon") then
weapon = v
end
end
end)
put local weapon variable inside of the remote Event function,
cuz whenever the player Respawns the local weapon will be set to nil since the localscript is located in StarterCharacterScripts
remoteEvent.OnServerEvent:Connect(function(player)
if player.Character == nil then return end
local weapon = nil
for i, child in player.Character:GetChildren() do
if collectionService:HasTag(child, "weapon") == false then continue end
weapon = child
break
end
print(weapon)
end)
I meant âStarterPlayerScriptsâ and itâs generally a bad idea to place server scripts inside the âStarterCharacterScriptsâ container (as their existence replicates to the client).
local char = script.Parent
RemoteEvent.OnServerEvent:Connect(function(plr, input, stamina)
local weapon
for i, v in pairs(plr.Character:GetChildren()) do
if CollectionService:HasTag(v ,"weapon") then
weapon = v
end
end
-- do something with the variable
end)
--not here
It does make your game more vulnerable, delete a server script inside your character from the perspective of the client, the deletion will replicate to the server (because clients have network ownership over their own characters).
--Script inside 'StarterCharacterScripts'.
while task.wait(3) do
print("Hello world!") --Stops printing once the script is deleted.
end