Script about a part appearing on my character isn't working

So, I have this script where I press the KeyCode “B” and it’s supposed to spawn a part on me but I don’t see it anywhere. Here’s my script:

StarterPlayer > StarterCharacterScripts > Local Script>

local uis = game:GetService(“UserInputService”)

uis.InputBegan:Connect(function(input,gpe)

if input.KeyCode == Enum.KeyCode.B then

end

end)

ServerScriptService > Script:

local uis = game:GetService(“UserInputService”)

local re = game:GetService(“ReplicatedStorage”):WaitForChild(“Room”)

uis.InputBegan:Connect(function(input,gpe)

if input.KeyCode == Enum.KeyCode.B then

re:FireServer()

end

end)

ServerScriptService > Script2:

local re = game:GetService(“ReplicatedStorage”):WaitForChild(“Room”)

local function createPart(player)
local Part = Instance.new(“Part”)
Part.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -10)
Part.Anchored = true
Part.Parent = game.Workspace
end

re.OnServerEvent:Connect(createPart)

I also inserted a RemoteEvent called “Room” in ReplicatedStorage

UserInputService only works on the client side; aka local scripts.
Your workflow should be something like this:

  • UserInputService event triggered with Enum.KeyCode.B
  • Fires a RemoteEvent to the server
  • Server picks it up, and then “add in the part” to player

So instead of local scripts I should use scripts?

Server cannot detect the user input as it is client sided and if you wanna make the part spawn on the server and not the client only we use remote event.
So on the local script if the input is the input you want then
remoteevent:FireServer()
On the serverscript pick the call up using

remoteevent.OnServerEvent:Connect(function(player)
--do whatever you want
end)

UserInputService only works on the client side, which only has local scripts
You need to use localscripts to handle user’s inputs etc and server script to do the rest.