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”)
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.
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?
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.
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)
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.
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!
@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