I'm trying to make a gui button that when pressed, will spawn a model at the player, however it doesn't work.
game.ReplicatedStorage.RemoteEvents.KillerTrap.OnServerEvent:Connect(function(player, partfolder, green) if player and partfolder then local newPart = script.StickModel:Clone() newPart.Name = player.Name.."'s Trap" newPart.Positon = player:FindFirstChild("HumanoidRootPart").Position newPart.Orietation = player:FindFirstChild("HumanoidRootPart").Orientation wait(3) newPart.Code.Disabled = false end end)
Okay, just to iron out a few potential problems, im going to tell the script to halt until the remote events and such exist.
--//Services local replicatedStorage = game:GetService("ReplicatedStorage") --//instances local remoteEvents = replicatedStorage:WaitForChild("RemoteEvents") local killerTrapRemote = remoteEvents:WaitForChild("KillerTrap") --//Functions local function giveModel(player, partFolder, green) if player and parFolder then local newPart = script:WaitForChild("StickModel"):Clone() newPart.Name = player.Name.."'s Trap" newPart.CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame newPart.Parent = workspace wait(3) newPart.Code.Disabled = false end end --//Connections killerTrapRemote.OnServerEvent:Connect(giveModel)
in your script, you werent accessing the player's character for the HumanoidRootPart, so I think that was the initial problem. To prevent any further issues, I added some functions that will make the script halt until they appear, so that you can avoid future errors similar to this.
When you use :FindFirstChild("HumanoidRootPart") on the player, it returns nil, because the player doesnt have a child called HumanoidRootPart. The character does, however.
game.ReplicatedStorage.RemoteEvents.KillerTrap.OnServerEvent:Connect(function(player, partfolder, green) if player and partfolder then local newPart = script.StickModel:Clone() newPart.Name = player.Name.."'s Trap" newPart.Position = player.Character:FindFirstChild("HumanoidRootPart").Position -- fixed typo newPart.Orientation = player.Character:FindFirstChild("HumanoidRootPart").Orientation -- fixed typo here too newPart.Parent = workspace -- sets parent (missed part) wait(3) newPart.Code.Disabled = false end end)