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