Hello, i have this script that spawns a trap, but it dosent spawn in? Can someone help?
local plr = script.Parent.Parent.Parent.Parent local mouse = plr:GetMouse() mouse.KeyDown:connect(function(Key) local k = Key:lower() if k == "CTRL" then if k == true then local trap = game.ServerStorage.Trap:Clone() trap.Parent = workspace trap.Position = plr.Character.LeftFoot plr.Character.Humanoid.Jump = true end end end)
Thanks!
Roblox does not recommend using mouse.KeyDown
as it is deprecated. Use UserInputService instead. Make sure it is a localscript.
local plr = script.Parent.Parent.Parent.Parent --So many parents local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input, GPE) --Input is self-explanatory, GPE stands for Game Processed Event. if GPE then return end --If the player is e.g. chatting, then do nothing. if input.KeyCode == Enum.KeyCode.LeftControl then local trap = game.ReplicatedStorage.Trap:Clone() --Serverstorage can only be accessed by server scripts. trap.Parent = workspace trap.Position = plr.Character.LeftFoot plr.Character.Humanoid.Jump = true end end)
If it doesn't work, then you should use remote events instead. Edit: bruh I posted an answer, and I also used comments to explain stuff.