What is the same in a server script to a mousebutton1click function? I want to transfer this entire script into a server script.
local Needed = 75
local player = game.Players.LocalPlayer
local titles = player.PlayerGui.ScreenGui.Frame.Titles
local Title = game.ReplicatedStorage:WaitForChild("Beast")
script.Parent.MouseButton1Click:Connect(function()
if de == true then
wait(0.01)
if player:WaitForChild("leaderstats").TopBounty.Value >= Needed then
de = false
wait(0.01)
for i,v in pairs(player.Backpack:GetChildren()) do
if v.Name == "WhiteBat" then
v:Destroy()
else
local Clone = game.ReplicatedStorage.Bats.WhiteBat:Clone()
Clone.Parent = player.Backpack
end
end
else
script.Parent.Text = "You Need ".. Needed.. " Top Bounty!"
wait(1)
script.Parent.Text = "White Wrath"
end
end
wait(0.77)
de = true
end)
You’re using a server script, so you can’t use local player. I would advise you to not use server scripts for UI elements; if you need to pass information between the server and the client then use an event
Just fire the server with the name of the tool. Then on the server side destroy all tools in the players backpack, Make the second parameter of the event named “tool name”, then using Bats:findfirstchild(toolname), you can clone it into their backpack.
I’m confused ()_(). Jack btw happy birthday. Umm so I make a event but how would I fire it? FireClients() FireServer() idk… And like where to put the script or if a local or server script should fire all these things IDK!
In the local script, when they press down fire the server. The reason for this is the server needs to handle the tool cloning, but there is no way for the server to know when they click on the button. Therefore, we use the client to send information to the server.
local de = true
local Needed = 75
game.ReplicatedStorage.BuyBatHH.WhiteBat.OnServerEvent:Connect(function(player)
local titles = player.PlayerGui.ScreenGui.Frame.Titles
local Title = game.ReplicatedStorage:WaitForChild("Beast")
if de == true then
wait(0.01)
if player:WaitForChild("leaderstats").TopBounty.Value >= Needed then
de = false
wait(0.01)
for i,v in pairs(player.Backpack:GetChildren()) do
if v.Name == "WhiteBat" then
v:Destroy()
else
local Clone = game.ReplicatedStorage.Bats.WhiteBat:Clone()
Clone.Parent = player.Backpack
end
end
else
player.PlayerGui.ScreenGui.Frame.Skins.WhiteBat.Text = "You Need " .. Needed.. " Top Bounty"
wait(1)
player.PlayerGui.ScreenGui.Frame.Skins.WhiteBat.Text = "White Wrath"
end
end
wait(0.77)
de = true
end)
Why is this making 3 clones?
for i,v in pairs(player.Backpack:GetChildren()) do
if v.Name == "WhiteBat" then
v:Destroy()
else
local Clone = game.ReplicatedStorage.Bats.WhiteBat:Clone()
Clone.Parent = player.Backpack
end
Because there’s 3 children in Backpack which name is not “WhiteBat” so it
clones 'WhiteBat" and parents it to player.Backpack 3 times instead
local Needed = 75
game.ReplicatedStorage.BuyBatHH.WhiteBat.OnServerEvent:Connect(function(player)
local titles = player.PlayerGui.ScreenGui.Frame.Titles
local Title = game.ReplicatedStorage:WaitForChild("Beast")
if de == true then
wait(0.01)
if player:WaitForChild("leaderstats").TopBounty.Value >= Needed then
de = false
wait(0.01)
if player.Backpack:FindFirstChild("WhiteBat") then
player.Backpack.WhiteBat:Destroy()
else
local Clone = game.ReplicatedStorage.Bats.WhiteBat:Clone()
Clone.Parent = player.Backpack
end
else
player.PlayerGui.ScreenGui.Frame.Skins.WhiteBat.Text = "You Need " .. Needed.. " Top Bounty"
wait(1)
player.PlayerGui.ScreenGui.Frame.Skins.WhiteBat.Text = "White Wrath"
end
end
wait(0.77)
de = true
end) ?
for i, v in ipairs(player.Backpack:GetChildren()) do
if v.Name == "WhiteBat" then
v:Destroy()
end
end
local Clone = game.ReplicatedStorage.Bats.WhitBat:Clone()
Clone.Parent = player.Backpack
This removes all tools named white bat, but only clones 1 white bat