Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part not spawning in your location after you press P?

Asked by 3 years ago

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.

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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

0
RemoteEvents are pretty cool! They have a lot of different uses. ElBamino 153 — 3y
0
Yea! TeaWithMee 76 — 3y
Ad

Answer this question