game.ReplicatedStorage.equipSword.OnServerEvent:Connect(function(player, sword) player.equippedSword.Value = sword end)
client/gui code
script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.equipSword:FireServer(game.Players.LocalPlayer, "Biograft") end)
When I fire the event in the gui while playing in studio this error pops up in the output,
invalid argument #2 (string expected got instance)
The sword is a string and it's supposed to change the player's equipped sword value to Biograft sword so that in the round they spawn with that sword. Any ideas on how to fix it?
This should help
So you're trying to when a player clicks a Gui object it fires a RemoteEvent to the server and changes the equippedSword value on the server so the value will be visible to the server, not just the client.
LocalScript:
script.Parent.MouseButton1Click:Connect(function() -- when GUI object clicked game.ReplicatedStorage.equipSword:FireServer("Biograft") -- fires to server passing a string value end)
ServerScript:
game.ReplicatedStorage.equipSword.OnServerEvent:Connect(function(client, sword) -- by default the `Client` parameter is always there by default player.equippedSword.Value = sword -- changes the equippedSword string value to "Biograft" end)
What you did before was weird because when doing the :FireServer()
function you don't need to give the player just the arguments you want to pass to the server.
More information on RemoteEvents
Any questions just reply below and explain what trying to do exactly.
This Is Just Because Your Sending A Player Instance If You Dont Know When Sending Remote Events The Recieving Script Automatically Gets The Player Instance To Fix It Just Do This
script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.equipSword:FireServer("Biograft") end)
Still Didnt Answered Your Problem Well Do This Then
game.ReplicatedStorage.equipSword.OnServerEvent:Connect(function(player, UniqueNameForString) player.equippedSword.Value = UniqueNameForString end)
The Problem Might Be Because You Might Have Another Instance Called "sword" And The Script Thinks That Your Talking About The Instance While Your Talking About The String Hope This Fixes It :D