Button that gives a tool after click

Hi there, I’m Crystallityy and I’m a beginner scripter on this platform, I am just working on a panel that gives a tool after click.

local Button = script.Parent.Parent.Bat
local fanta = game.Lighting.Bat
local Player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	print("Event fired")
	local fantaClone = fanta:Clone()
	fantaClone.Parent = Player.Backpack
	print("Gave "..Player.Name.." the Bat") 
end)

The script (local script) is working, but a bat does no damage. Is it a script problem?

I think you have to use RemoteEvent to give the tool since I believe the tool is local/shows for you only. Create a RemoteEvent that fires to give you the tool so it’s created on the Server

1 Like

I believe you’re only Cloning the fantaClone variable to your client side, which would work wonky in a bunch of different ways (Haha camera server go wonky)

If your Tool works fine, you can use a RemoteEvent to send the weapon from the client to the server so that it works server-sided that way

local Button = script.Parent.Parent.Bat
local Player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Button.MouseButton1Click:Connect(function()
	print("Event fired")
    Event:FireServer()
end)
--Random Server Script in ServerScriptService
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local fanta = game.Lighting.Bat

Event.OnServerEvent:Connect(function(Player)
	print("Gave "..Player.Name.." the Bat") 
	local fantaClone = fanta:Clone()
	fantaClone.Parent = Player.Backpack
end)

FireServer() can be called on the client, and OnServerEvent() can be called on the server with the Player as the first argument

Ok why are you all so quick with your answers I swear to everything

4 Likes

Thank you dude, it works! :grinning_face_with_smiling_eyes:

1 Like

Yea, I don’t know how people are that quick lol.