Why is this 1 line script not working, no error is printed either?

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).

yes i did the print in the script

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)

Nothing got printed

Please retry:

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.

Not working either its not printing anything

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:

game.ReplicatedStorage.SpawnCarEvent:FireServer(mouse.Hit,1)

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.

Your LocalScript is most likely incorrectly parented, it’s not working at all on the client. Where is it parented to?

its in the tool, and the tool dont have anything else like handle

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)

As I said in my previous post, testing the equipped event by adding a print will make sure the equipped is working properly.

Here’s the correct use of mouse.Hit:

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

equipped is not working, lol its not working

Where did you put both scripts?

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.

I put local script in tool, remote event in replicated storage and remote event script in server script service image

Maybe try printing something at Line 1 of both scripts to see if they actually work or not

1 Like

Okay, then are you actually duplicating the tool into your backpack, and equipping the tool in playtest?

(Really stupid question, I know, but this doesn’t make sense otherwise)

1 Like

i am buying the car tool from shop gui and then equipping it, nothing works

it printed

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)

but does not work the equipped function