Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[URGENT] Click for Tool if Leaderstats?

I have a script and Its supposed to give a tool to a player if they have a certain amount of Cash, (in this case Cash is Bills) and if they click the button

So if the player clicks the button, and they have enough bills, then the sword (Sword1) is cloned and put into the players backpack.

How ever the script i have here does not work, does anybody know why it wont?

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
		if player:WaitForChild("leaderstats").Bills.Value == script.required.Value then
		game.ServerStorage.Sword1:Clone().Parent = player:WaitForChild("Backpack")
	end
end)

Things to remember:

The script is a local script

It has a number value called "required" which value is 100 and is parented to the local script

The sword is located in the ServerStorage

This is what the hierarchy looks like

1 answer

✓ Accepted answer

You should use a RemoteEvent to grant the sword so it's replicated to the server.

Local Script

local Remote = game.ReplicatedStorage:WaitForChild("REMOTEHERE")

script.Parent.MouseButton1Click:Connect(function()
    local player = game.Players.LocalPlayer
        if player:WaitForChild("leaderstats").Bills.Value >= script.required.Value then -- if their bill is greater than the value then it countinues   
        Remote:FireServer() -- fires remote
    end
end)

Normal Script

local Remote = game.ReplicatedStorage:WaitForChild("REMOTEHERE")

Remote.OnServerEvent:Connect(function(player)
	if player:WaitForChild("leaderstats").Bills.Value >= script.required.Value then -- if their bill is greater than the value then it countinues        									 		 	 
 		local tool = game.ServerStorage:WaitForChild("Sword1"):Clone()
		tool.Parent = player.Backpack or player:WaitForChild("Backpack")
	end
end)

You need to create a remote event and put it in replicatedstorage. Then where it says REMOTEHERE in both scripts put the name of the remote there.

You also need to create a new script and put it inside ServerScriptService and put the code under Normal Script inside of it. As for the local script just simply copy the code under localscript and put it inside of their.

These two scripts were written in this chatbox so sorry if they're messy!

2 comments

0

Yo dude tysm is worked <3

0

@PurpleProgram No problem, glad I could help! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.