#Tool script

1 messages · Page 1 of 1 (latest)

craggy pike
#

So I’m trying to make a weapon tool, basically what I have right now is a GUI button, the tool is in replicated storage, when you click the button it gives you a clone of the tool and puts it in your backpack. I have that all working but when I try to add a script for the tool, nothing happens, I’ve tried using only a print, but not even that works

(The script in the tool is a server script)

dark gorge
craggy pike
#

Script for button: (In local script)
local team1button = script.Parent
local tool = game.ReplicatedStorage.Tool
local player = game.Players.LocalPlayer
local backpack = player.Backpack

team1button.MouseButton1Click:Connect(function()
local toolclone = tool:Clone()
toolclone.Parent = backpack
script.Parent.Parent.Enabled = false
end)

#

Script for tool: (In server script)
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local function equipped()
print("This is working")
end

tool.Equipped:Connect(equipped())

solemn crest
#

that's because you're referencing the original tool when you made a copy of it in the client, that's why nothing is happening

#

reference the copied tool in the server script however seems fit

craggy pike
#

@solemn crest Do I use an instance.new? Because I thought cloning a tool from replicatedstorage meant that it would apply to the cloned tools

solemn crest
craggy pike
solemn crest
#

no the toolclone variable can stay the same :P

craggy pike
#

and i put the code in the buttons script or the tools script

#

@solemn crest

solemn crest
#

put the local script preferrably in the button

#

and the script in the server script service

craggy pike
#

Because I don’t have a tool clone variable on the server script, the script for the tool

#

@solemn crest Sorry man I still don’t really understand how this works

solemn crest
#

this is how your set up should look like:

craggy pike
#

And i put the code you gave me in serversciptservice script?

torn perchBOT
#

studio** You are now Level 3! **studio

solemn crest
#

mb

torn perchBOT
#

studio** You are now Level 3! **studio

solemn crest
#

you also need a remote event in replicated storage

#

took a while to try and think of what you're trying to do so I don't write a script that doesn't work for what you want

#

do something like this:

In your local script:

local team1button = script.Parent
local tool = game.ReplicatedStorage.Tool
local player = game.Players.LocalPlayer
local backpack = player.Backpack
local remote = game.ReplicatedStorage.giveTool

team1button.MouseButton1Click:Connect(function()
    local toolclone = tool:Clone()
    toolclone.Parent = backpack
    script.Parent.Parent.Enabled = false
    
end)

local toolcloneCreated = backpack:WaitForChild("Tool", math.huge)

toolcloneCreated.Equipped:Connect(function()
    remote:FireServer()
end)

then in your server script:

local remote = game.ReplicatedStorage.giveTool

remote.OnServerEvent:Connect(function(plr)
    print("This is working")
end)
#

hope the script does what you wanted it to do

craggy pike
#

Thanks, but i dont really see how remoteevent helps here, since I'm simply trying to make it so the tool can print something when it's equipped