Dropping a model from ServerStorage using gear wont work

Hello. I was trying to make droppable explosives for my game when I tried to script the gear, I fail (like I always do lol).
Heres the script:

local bomb = game.ServerStorage.tool_thing.explosive
local button = script.Parent

local function GetCharacter(plr : Instance)
	local character = plr.Character
	if character then
		return character
	end
end

button.MouseButton1Click:Connect(function()
	local clone1 = bomb:clone()
	if clone1 then
		if Character then
			if Character:FindFirstChild("HumanoidRootPart") then
				clone1:SetPrimaryPartCFrame(CFrame.new(Character.HumanoidRootPart.Position + Vector3.new(0, 0, -17)))
			end
		end
	end
end)

Also it sent no output.

1 Like

Question,

Why use that? You cloned it, so it’ll exist

Second,

Character was never defined there?

Lastly, have you tried using prints/warns? They’re very helpful lol…
Example:

local character = player.Character
if not character then warn( ("Character for %q returned nil"):format(player.Name) ) return end
1 Like

just set the clone parent to workspace so that it is visible to players,

clone1.Parent = workspace

I also recommend using local scripts and remote events to communicate between server and client as it is a bad practice to control UI using a server script.

1 Like

Does not work. The explosive isn’t visible in the workspace.
Also it sent no output.

1 Like

Anything in server storage doesn’t replicate to the client. You can move your bomb to replicated storage then change:

local bomb = game.ServerStorage.tool_thing.explosive

to

local bomb = game.ReplicatedStorage.tool_thing.explosive

and then it should work.

2 Likes

Thanks, but I wanted it to spawn infront of the player.
Also I changed the script a lil:

local bomb = game.ReplicatedStorage.tool_thing.explosive
local button = script.Parent

local function GetCharacter(plr : Instance)
	local character = plr.Character
	if character then
		return character
	end
end

button.MouseButton1Click:Connect(function(plr)
	local clone1 = bomb:clone()
	if clone1 then
		clone1.Parent = game.Workspace
		local player = GetCharacter(plr)
		if player then
			if player:FindFirstChild("HumanoidRootPart") then
				clone1:SetPrimaryPartCFrame(CFrame.new(player.HumanoidRootPart.Position + Vector3.new(0, 0, -17)))
			end
		end
	end
end)

The explosive isn’t spawning infront/near the player.

1 Like

You should really consider using RemoteEvents to communicate from client to server and vice versa, I’d recommend having the gear run on a LocalScript and interact with a RemoteEvent inside ReplicatedStorage where a server script inside ServerScriptService will parse necessary information and connection refs, you can then choose to use Event:FireAllClients() or you can filter through a table of players using Players:GetPlayers to make only certain people see it.

RemoteEvents really are a lifesaver. If you need more of an explanation let me know.

2 Likes

Uh sure. I would like to have a explanation.

1 Like

My apologies for the late reply.

I’ll cater an explanation to what it is that you specifically want to achieve but I will need a bit of help from you, could show me how you are currently handling your tool so I can best adapt a possible solution? This includes whether you are using remotes, server scripts and local scripts.

1 Like

You have a function GetCharacter, but u dont use it, also Character variable is nil.

1 Like

This is where local Character = Player.Character or Player.CharacterAdded:Wait() comes in handy.

1 Like

I am currently handling it on a ServerScript for it to be visible to other players.