Mouse Button 1 Click Server Script Equivalent

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)
1 Like

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

2 Likes

How would I fire and event just for the tool to be cloned? I really need help with this.

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.

Not only will you clone the tool on the server but you should also be changing your values on the server as well

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.

Got it. How would I find the player then?

When you’re using a RemoteEvent to go from Client to Server, in the server script you do this

game.ReplicatedStorage.YourEvent.OnServerEvent:Connect(function(plr)

end)

when you do that you can automatically get the player, not sure if this helps but ok.

What about using a remote function? That returns the signal to the player that triggered after the Server function is finished?

Oh ok thanks! :smiley: I’ll try that out rq. If not ill come back rq.

Whenever you fire the server, the first parameter is automatically the player. I’m on mobile so this will be bad formatting:

Local Script

Local food1 = “pizza”
Local food2 = “burger”
Remotevent:FireServer(food1, food2)

Server Script:

Remotevent.OnServerEvent:Connect(function(player, word1, word2)
print(player, word1, word,2)

   Prints(BMWLux, pizza, burger)

end)

how would I fire it? Like :FireServer()

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

1 Like

How could I fix this? Just take out the white bat thing? I mean I want the person to only have 1 white bat though…

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) ?

after wait(0.01),

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

however i believe your solution works fine

You would fire it like this

game.ReplicatedStorage.YourEvent:FireSever()