Here is my script. It works like this but i don't want other players to be able to click and get money if they don't have a key.
key is called "Blue Master Key" and it is a tool that player holds in hes inventory.
function onClicked() for i=1, 1 do for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("Xp") then player.Cash.Cash.Value = player.Cash.Cash.Value + 2000 end end end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Hello, kexiGamer!
You have to use this script:
function onClicked() for _, player in ipairs(game.Players:GetPlayers()) do if player.Backpack:FindFirstChild("Blue Master Key") and player.Backpack:FindFirstChild("Blue Master Key"):IsA("Tool") then player.Cash.Cash.Value = player.Cash.Cash.Value + 2000 end if game.Worspace[player.Name]:FindFirstChild("Blue Master Key") and player.Backpack:FindFirstChild("Blue Master Key"):IsA("Tool") then player.Cash.Cash.Value = player.Cash.Cash.Value + 2000 end end end) script.Parent.ClickDetector.MouseClick:connect(onClicked)
Attention: This script will change the money value of ALL players
This another one jsut changes the stats of who clicked!
function onClicked(Clicker) if Clicker.Backpack:FindFirstChild("Blue Master Key") and Clicker.Backpack:FindFirstChild("Blue Master Key"):IsA("Tool") then Clicker.Cash.Cash.Value = Clicker.Cash.Cash.Value + 2000 end if game.Workspace[Clicker.Name]:FindFirstChild("Blue Master Key") and Clicker.Backpack:FindFirstChild("Blue Master Key"):IsA("Tool") then Clicker.Cash.Cash.Value = Clicker.Cash.Cash.Value + 2000 end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Good Luck with your games!
Ok so, since you want to see if they have the key in their backpack, were are gonna use the argument that is passed when the MouseClick
event is fired.
Here is what I mean :
part.ClickDetector.MouseClick:Connect(function(playerWhoClicked) --It gives us the player who clicked here print(playerWhoClicked) end)
Since we can get the player like this, we can then access their backpack and see whether they have the key or not.
function onClicked(playerWhoClicked) local player = playerWhoClicked --Storing the player local backpack = player.Backpack -- Their Backpack if backpack:FindFirstChild('Blue Master Key') then -- looks for the key --Since its found the key, it can do the next bit if player:FindFirstChild("Xp") then player.Cash.Cash.Value = player.Cash.Cash.Value + 2000 end else print('No key found') --No key found end end script.Parent.ClickDetector.MouseClick:Connect(onClicked)