Tool giving button script not working

Hello there users! I am kind of new to scripting, so I have absolutely no clue how to fix error…if anyone could help me that would be amazing!

So I plan to copy and paste this into multiple GUI buttons, but for now this is the one for the medkit button. And yes I double check the folder that the tools are in is called Tools, and the medkit tool is called Medkit. Just some errors with the end needing then, but I don’t need/want a then because there is nothing more to add to the script!

Like I said if anyone can correct the script below, that would be spectacular.

game.Players.CharacterAdded:Connect(function(Player)
	if script.Parent.MouseButton1Click:Connect(function()
			local clonetool = game.ServerStorage.Tools.Medkit:Clone()
			clonetool.Parent = game.Players[Player.Name].Backpack
end)

Error msg:
image

Server storage tool & folder:
image

1 Like
game.Players.CharacterAdded:Connect(function(Player)
	script.Parent.MouseButton1Click:Connect(function()
		local clonetool = game.ServerStorage.Tools.Medkit:Clone()
		clonetool.Parent = game.Players[Player.Name].Backpack
	end)
end)

Try this.

1 Like

Why do you have an event in an if statement? You don’t need that, you just need to make the event.

Also if this is in a GuiButton, no need for the CharacterAdded event, jsut put the MouseButton1Click

local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local clonetool = game.ServerStorage.Tools.Medkit:Clone()
	clonetool.Parent = Player.Backpack
end)

But you’ll also realise that this wont work either, because you’re most likely locally trying to get the tool from ServerStorage, the client cna’t see inside of ServerStorage, so you’ll need a RemoteEvent to properly get the tool from the server, and also because cloning a tool from the client will break it sfunctionality.

And plus even if this was a server script, you’d have no way of getting the player who clicked the button so it’s definitely local

3 Likes

Adding on what to Embat said, you’d want to go about it like this:

Have a script called ToolHandler in the workspace with the code below. The ToolHandler should have a RemoteEvent inside.

script.RemoteEvent.OnServerEvent:Connect(function(player, tool)
	local clonetool = game.ServerStorage.Tools:FindFirstChild(tool)
	clonetool:Clone().Parent = player.Backpack
end)

Your button’s local script should look like this:

script.Parent.MouseButton1Click:Connect(function()
	game.Workspace.ToolHandler.RemoteEvent:FireServer("Medkit")
end)
1 Like

Hey hey hey! I was looking at your post!!

2 Likes

Alright so I have looked at it and took note that the server script service script is for just the medkit, I need 6 tools on that script. And spacemonkey had the best script, because his has like a one script fits all if you noticed…

@8Alex8Friend thank you so much, you’re a huge help!

1 Like