I want to send the player’s character to the server when they press a button so that I can make them morph.
I only want to do this for that one player, that specific character.
I have tried doing this before but it turns everyone into the morph so I came here to see if anyone could be able to help me out.
1 Like
-- LOCAL SCRIPT --
local UIS = game:GetService("UserInputService")
local replStorage = game:GetService("ReplicatedStorage")
local keyRemote = replStorage:WaitForChild("KeyRemote")
UIS.InputBegan:Connect(function(input, proc)
if input.KeyCode == Enum.KeyCode.A then --a button pressed
keyRemote:FireServer()
end
end)
-- SERVER SCRIPT --
local replStorage = game:GetService("ReplicatedStorage")
local keyRemote = replStorage:WaitForChild("KeyRemote")
keyRemote.OnServerEvent:Connect(function(player)
local character = player.Character
--do stuff with character
end)
Copy local script code into a local script, place it inside the StarterPlayerScripts folder, copy the server script code into a server script, place it inside the ServerScriptService folder, finally make a RemoteEvent instance named “KeyRemote” and put it inside the ReplicatedStorage folder.
2 Likes
Ah, I see, I was getting the player with the “.PlayerAdded”. Thanks!
No problem, whenever a client fires the server inside a local script through calling the FireServer() function the player instance associated with that particular client is automatically sent to whatever function is connected to the OnServerEvent event handler inside the server script.