Button that gives weapons

  1. What do you want to achieve? Button that gives weapons

2.What is the issue? Button doesn’t give weapons.

3.What solutions have you tried so far? Tweaking the code which made it worse and devforum

My code so far:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local ServerStorage = game:GetService(“ServerStorage”)

local Event = ReplicatedStorage:WaitForChild(“RemoteEvent”)
local Wand = ServerStorage.Tools:WaitForChild(“BeginnerWand”)
local BowTool = ServerStorage.Tools:WaitForChild(“Bow”)

Event.OnServerEvent:Connect(function(player, ToolName)
print(“Event notification received”)

if player.Backpack:FindFirstChild(ToolName) then
	print(ToolName.." is already owned")
	return
end

if ToolName == "BeginnerWand" then
	local CloneWand = Wand:Clone()
	CloneWand.Parent = player.Backpack
	print("Weapon "..ToolName.." has been owned")

elseif ToolName == "Bow" then
	local CloneBow = BowTool:Clone()
	CloneBow.Parent = player.Backpack
	print("Weapon "..ToolName.." has been owned")
end

end)

This is to check if there is a duplicate tool if there is it will remove and/or stop the player from getting extra duplicites.

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local Event = ReplicatedStorage:WaitForChild(“WandEvent”)

local Button = script.Parent

Button.Activated:Connect(function()

Event:FireServer(“BeginnerWandEvent”)

Button.Parent.Visible = false

end)

This is a local script to call a remote function which should give the weapon which its not. I have a folder named tools so that the script has a reference to the tools I want to give but it doesn’t work.

1 Like
If It Is a Brick

In your button your meant to add a click detector if it is a brick
image

then in your code

instead of that you do
Button.ClickDetector.MouseClick:Connect(function()

However if it is a textbutton

Button.MouseButton1Click:Connect(function()

1 Like

I used the second one i thought hmmmmmmm lemme get back to you.

sorry my layout was bad i updated it a little

It didn’t work, I still don’t get the tool, it doesnt make sense bc it was working yesterday till I edited the code to add a new tool.

can I see the code and the explorer menu

try this
ToolTest.rbxl (31.2 KB)

1 Like

He used getservice which works too
ServiceProvider:GetService (roblox.com)

We have discussed this before, but the problem is that you are firing the wrong remote event, and using OnServerEvent on a different remote event. That is why you are not getting your tools.
Before I continue, are there any errors in the output from any of the scripts you have provided?

1 Like

No error I tried to contact you but it wouldn’t work could you send me the old script and adapt it to have an extra slot for a new weapon please? Thank you and no there are no errors.

1 Like

Okay. Im not sure which remote event you are meant to use, but let’s just use the BeginnerWandEvent.

For your local script that is under the Wand button, use this following code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("BeginnerWandEvent")
local Button = script.Parent

Button.Activated:Connect(function()
	Event:FireServer("BeginnerWand")
	Button.Parent.Visible = false
end)

And for the other local script that is inside the Bow button, use this following code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("BeginnerWandEvent")
local Button = script.Parent

Button.Activated:Connect(function()
	Event:FireServer("Bow")
	Button.Parent.Visible = false
end)

Now for your server script, use this code below:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

local Event = ReplicatedStorage:WaitForChild("BeginnerWandEvent")
local Wand = ServerStorage.Tools:WaitForChild("BeginnerWand")
local BowTool = ServerStorage.Tools:WaitForChild("Bow")

Event.OnServerEvent:Connect(function(player, ToolName)
	if player.Backpack:FindFirstChild(ToolName) then
		print(ToolName.." is already owned")
		return
	end

	if ToolName == "BeginnerWand" then
		local CloneWand = Wand:Clone()
		CloneWand.Parent = player.Backpack
		print("Weapon "..ToolName.." has been owned")

	elseif ToolName == "Bow" then
		local CloneBow = BowTool:Clone()
		CloneBow.Parent = player.Backpack
		print("Weapon "..ToolName.." has been owned")
	end	
end)
1 Like

I have one more question @BabyNinjaTime how would I disable the button forever even if they rejoin?

You would have to add a debounce value for every player then save that value using data store. Then next time they join if the value is true show the button.

1 Like

Can you show me how to assign a number to every player who pressed the button and how to save it please? Thank you!

I can’t really type out the code because I’m on mobile and it would take hours to make a data store script typing like this. Real sorry, Hopefully someone else can!

1 Like

No problem @bostnm Im sure I can figure out a way.

@BabyNinjaTime It stopped working… can you check the code one more time please?
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local ServerStorage = game:GetService(“ServerStorage”)

local Event = ReplicatedStorage:WaitForChild(“BeginnerWandEvent”)
local Sword =ServerStorage.Tools:WaitForChild(“Sword”)
local Wand = ServerStorage.Tools:WaitForChild(“BeginnerWand”)
local BowTool = ServerStorage.Tools:WaitForChild(“Bow”)

Event.OnServerEvent:Connect(function(player, ToolName)
if player.Backpack:FindFirstChild(ToolName) then
print(ToolName…" is already owned")
return
end

if ToolName == "BeginnerWand" then
	local CloneWand = Wand:Clone()
	CloneWand.Parent = player.Backpack
	print("Weapon "..ToolName.." has been owned")

elseif ToolName == "Bow" then
	local CloneBow = BowTool:Clone()
	CloneBow.Parent = player.Backpack
	print("Weapon "..ToolName.." has been owned")
	
elseif ToolName == "Sword" then
	local CloneSword = Sword:Clone()
	CloneSword.Parent = player.Backpack
	print("Weapon "..ToolName.." has been owned")
end	

end)

Any errors this time? I dont see any problem with the script

2 Likes

No errors could you please look it over as I have made some changes if you are unaware. Maybe I forgot to a add remote function?