✓ Accepted answer
The player on :FireServer() is already sent as a parameter, so all you have to do is send the extra arguments.
LocalScript, and for the .OnServerEvent() the first parameter passed through is the player, so it will be...
RemoteEvent.OnServerEvent:Connect(function(player, extraArguments)
print(player.Name)
end)
So, in the LocalScript you don't have to pass through the player, but you will have to pass through the other arguments. In the ServerScript you will have to identify the player as the first parameter passed through.
So, this is how your script should look like.
LocalScript
local remote = game:GetService("ReplicatedStorage"):WaitForChild("KnifeChange")
script.Parent.MouseButton1Click:Connect(function()
local knifeName = script.Parent
remote:FireServer(knifeName.Text)
end)
ServerScript
local remote = game:GetService("ReplicatedStorage"):WaitForChild("KnifeChange")
local currentKnife = game:GetService("ReplicatedStorage"):WaitForChild("CurrentKnife")
remote.OnServerEvent:Connect(function(player,knife)
currentKnife.Value = knife
end)
Common Mistakes
Make sure you are using a StringValue to change the name
Make sure you are using the correct directories, names, etc.
Hope this helped! Feel free to select this as an answer if this worked for you!
2 comments
Thank you! Worked exactly how I wanted it!
No problem! Glad to help!