So i made a spawner. If you click G, it spawn one car in front of your head. But it spawns too much, it spawns 4 of them. whats the problem?
script:
local debounce = false
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()
debounce = false
end
end
end)
end)

4 comments
Your script is extremely wrong. You have UserInputService and LocalPlayer on the server which obviously won't work.
but it does work.
then how do i use userinputservice with onserverevent?
It worked because you were using Play Solo.