Its a local script if player equips it using keyboard their mouse position gets fired to server, vehicle spawns in that position, its not working.
Local script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Equipped:Connect(function()
game.ReplicatedStorage.SpawnCarEvent:FireServer(mouse.Hit,1) -- second argument is car number if its 1 then first car, if 2 second car
end)
Script:
game.ReplicatedStorage.SpawnCarEvent.OnServerEvent:Connect(function(plr,cframe,carnumber)
if carnumber == 1 then
local clone = game.ReplicatedStorage.Vehicles.BasicCar:Clone()
clone.Parent = game.Workspace
clone:SetPrimaryPartCFrame(cframe + Vector3.new(0,10,0))
plr.Backpack:FindFirstChild("Basic Car"):Destroy()
end
end)
Can you try printing something on the server side so that you can know if it actually fires the remote event? If it fires, then that means that there’s something wrong with the server script. If it doesn’t fire, then that means the local script didn’t fire the event properly (or the server script didn’t receive the event properly).
game.ReplicatedStorage.SpawnCarEvent.OnServerEvent:Connect(function(plr,cframe,carnumber)
if carnumber == 1 then
print("Going to spawn car")
local clone = game.ReplicatedStorage.Vehicles.BasicCar:Clone()
clone.Parent = game.Workspace
clone:SetPrimaryPartCFrame(cframe + Vector3.new(0,10,0))
plr.Backpack:FindFirstChild("Basic Car"):Destroy()
end
end)
game.ReplicatedStorage.SpawnCarEvent.OnServerEvent:Connect(function(plr,cframe,carnumber)
print("Going to spawn car")
if carnumber == 1 then
local clone = game.ReplicatedStorage.Vehicles.BasicCar:Clone()
clone.Parent = game.Workspace
clone:SetPrimaryPartCFrame(cframe + Vector3.new(0,10,0))
plr.Backpack:FindFirstChild("Basic Car"):Destroy()
end
end)
This is to check if the issue is with the value of carnumber, perhaps the if statement is wrong, and that’s why it is not printing.
First, let’s see if your equipped is not working correctly for some reason. Add the print line to your code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Equipped:Connect(function()
print("Tool Equipped")
game.ReplicatedStorage.SpawnCarEvent:FireServer(mouse.Hit,1) -- second argument is car number if its 1 then first car, if 2 second car
end)
If it prints, then there is probably something wrong with your use of mouse.Hit in your FireServer, right here:
I can’t be sure about this, but I would look up the uses of mouse.Hit and see what form it comes in. I will be sure to get back to you if I figure it out myself.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Equipped:Connect(function()
print("Tool equipped")
local success,errormessage = pcall(function()
game.ReplicatedStorage.SpawnCarEvent:FireServer(mouse.Hit.Position,1)
end)
if not success then
print(errormessage)
end
end)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Equipped:Connect(function()
print("Tool equipped")
local success,errormessage = pcall(function()
game.ReplicatedStorage.SpawnCarEvent:FireServer(mouse.Hit.p,1)
end)
if not success then
print(errormessage)
end
end)
As far as I can tell from the API page, it’s just mouse.Hit.p, not mouse.Hit.Position
Alright, then I would just make sure the localscript for the tool is directly parented to the tool. That is about it. Post a screenshot of your hierarchy if you need help.
print("Hey local script is working")
print("it really works")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Equipped:Connect(function()
print("Tool equipped")
local success,errormessage = pcall(function()
game.ReplicatedStorage.SpawnCarEvent:FireServer(mouse.Hit,1)
end)
if not success then
print(errormessage)
end
end)