I have a few suggestions that might fix your issue.
Maybe it doesn't work because somehow, due to latency, EquippedTool or EquippedPrimary is set later than the ServerEvent firing? Maybe EquippedPrimary and/or EquippedTool is invisible to the server? I suggest trying out a test server to make sure the latter isn't the issue.
Other than that, I'm kind of confused why another local script would fire that server event. If it's meant to fire on the mouseclick, why not just do it in the same script? Also, it looks like by using these values, you're trying to pass some sort of argument through to the server. That is a rather shady and inefficient way of doing it. You can also just literally pass the argument with your ServerEvent, like so:
LocalScript:
01 | script.Parent.MouseButton 1 Click:Connect( function () |
02 | game.Players.LocalPlayer.EquippedTool.Value = script.Parent.Name |
03 | script.Parent.BorderSizePixel = 5 |
04 | script.Parent.ZIndex = 2 |
05 | for i, image in pairs (script.Parent.Parent:GetChildren()) do |
06 | if image.Name ~ = script.Parent.Name then |
08 | image.BorderColor 3 = Color 3. new( 0 , 0 , 0 ) |
09 | image.BorderSizePixel = 1 |
12 | script.Parent.BorderColor 3 = Color 3. new( 255 , 0 , 0 ) |
13 | game:GetService( "ReplicatedStorage" ):WaitForChild( "SpawnEvent" ):FireServer(game.Players.LocalPlayer.EquippedTool.Value, game.Players.LocalPlayer.EquippedPrimary) |
ServerScript:
1 | game:GetService( "ReplicatedStorage" ):WaitForChild( "SpawnEvent" ).OnServerEvent:Connect( function (player, EquippedTool, EquippedPrimary) |
2 | if EquippedPrimary = = "" then |
5 | local primary = game.ServerStorage [ EquippedTool ] :Clone() |
6 | primary.Parent = player.Backpack |
The above will deal with both of the issues that I stated earlier, latency won't cause errors, because you're passing the arguments with that very ServerEvent, and it also doesn't matter anymore that those things might be invisible to the server.