I made a spawner, but when i click G, it wont do anything.
first script (at the startergui):
local uis = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local name = plr.Name..("'s Car") local debounce = false uis.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.G then for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren())do if v:IsA("Model") and v.Name == name then v:Destroy() end end end end) uis.InputEnded:Connect(function(aey) wait() game.ReplicatedStorage.SpawnCarEvent:FireServer() end)
second script(at the workspace):
local debounce = true local uis = game:GetService("UserInputService") game.ReplicatedStorage.SpawnCarEvent.OnServerEvent:Connect(function(plr) uis.InputBegan:connect(function(aey) if aey.KeyCode == Enum.KeyCode.G then if not debounce then wait() local car = plr.SelectedCar.Value:Clone() car.Parent = game.Players.LocalPlayer.Character car.Chassis.Base.Anchored = true car.Name = plr.Name..("'s Car") car:SetPrimaryPartCFrame(plr.Character.Head.CFrame * CFrame.new(0,0,-10)) car:MakeJoints() car.Chassis.Base.Anchored = false debounce = true wait(0.1) debounce = false end end end) end)
thanks for helping!
Your second script is where the problem is at
"not" will reverse the boolean value ,
your debounce at the beggining is true, so when you put if not debounce then
it means if false then
, which of course will not run as the value is false
Also you UserInputService doesnt work in server scripts
local debounce = true game.ReplicatedStorage.SpawnCarEvent.OnServerEvent:Connect(function(plr) if debounce then wait() local car = plr.SelectedCar.Value:Clone() car.Parent = game.Players.LocalPlayer.Character car.Chassis.Base.Anchored = true car.Name = plr.Name..("'s Car") car:SetPrimaryPartCFrame(plr.Character.Head.CFrame * CFrame.new(0,0,-10)) car:MakeJoints() car.Chassis.Base.Anchored = false debounce = true wait(0.1) debounce = false end end)