Hello, I'm trying to make a tool that gives the player a Roblox gear when it's clicked using InsertService, but it has to be in a server script for that to work. Does the script have to be a localscript for getting the player's mouse?

Also, the tool works fine in Studio, but in-game it prints "Equipped" and "Found player" and then nothing else.

Here's the script (serverscript)

gears = {170896461, 257810065, 365674685, 319656339}

local Tool = script.Parent


	Tool.Equipped:connect(function(Mouse)
	print("equipped!")	
	local ply = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	print("found player!")
	Mouse.Button1Down:connect(function()
		print("mouse down!")
		wait(1)
        local model = game:GetService("InsertService"):LoadAsset(gears[math.random(#gears)])
			for _,v in pairs(model:GetChildren()) do
                if v:IsA("Tool") or v:IsA("HopperBin") then
                    v.Parent = ply.Backpack
						print("got model!")
						script.Parent:Destroy()

	end
	end
	end)
	end)

5 comments

1

Why are you handling a tool inside of a Server Script?

1

You should never need the player's mouse from the server, it's just illogical. You should consider moving all of this to a local script, where it belongs. Same goes for any other code specific to a single user.

1

If you need to do something from a server script just use a remote event or a remote function

0

I've been told that :LoadAsset only works on a server script, I'm not totally sure how to use remote events, but I'll look into it.

0

Here's a video tutorial I made on them: https://www.youtube.com/watch?v=4Dc_bri9mjs