game:GetService("UserInputService").InputBegan:Connect(function(input) if input.KeyCode.Name == "P" and game.Players.LocalPlayer.Character then local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoidRootPart = character:WaitForChild("HumanoidRootPart") while humanoidRootPart do local Part = Instance.new("Part") Part.Parent = workspace Part.Material = Enum.Material.Glacier Part.Position = humanoidRootPart.Position end end) end) end end)
When I press P, it won't spawn a part in the players location.
I would recommend firing the event in a local script and putting what you want to happen in a server script reciving the event
So
LocalScript:
game:GetService("UserInputService").InputBegan:Connect(function(input) if input.KeyCode.Name == "P" and game.Players.LocalPlayer.Character then game.ReplicatedStorage.*EventName*:FireServer() --Fires event from local script to server script end)
ServerScript:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) --Reciving the event after fired local char = game.Workspace:FindFirstChild(plr.Name) --Finds the player in the workspace local humanoidRootPart = char:FindFirstChild("HumanoidRootPart") --Finds the RootPart in the character local Part = Instance.new("Part") --Creates new part Part.Parent = workspace --Info For parts Part.Material = Enum.Material.Glacier Part.Position = humanoidRootPart.Position end)
Learn more about remote events here