Hi, I have a script so that after 10 clicks on a block, a coin will drop out and it will add coins to the player. Now any player can pick up a coin, how to make that the dropped coin can be picked up only by the one who made more clicks?
Script for that the coin drops out after 10 clicks
local coal = script.Parent
local coal1 = script.Coal5
local coal2 = script.Coal6
local coal3 = script.Coal7
local coal4 = script.Coal8
local click = coal.ClickDetector
local clickAmount = 0
local canClick = true
local function addClick(player)
if canClick then
player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + player.leaderstats.Level.Value
clickAmount = clickAmount + player.leaderstats.Level.Value
end
if clickAmount >= 10 then
local num = math.random(1,2)
if num == 1 then
local toast=script.Parent.toast:clone()
toast.Parent=game.Workspace
toast.Transparency=0
toast.Locked=false
toast.Anchored=false
toast.CanCollide=true
local offsetCFrame = CFrame.new(0, 3, 0) * CFrame.Angles(0, 0, 0)
toast.CFrame = coal.CFrame:ToWorldSpace (offsetCFrame)
print("Hello")
elseif num == 2 then
local toast=script.Parent.toast:clone()
toast.Parent=game.Workspace
toast.Transparency=0
toast.Locked=false
toast.Anchored=false
toast.CanCollide=true
local offsetCFrame = CFrame.new(0, 3, 0) * CFrame.Angles(0, math.rad(90), 0)
toast.CFrame = coal.CFrame:ToWorldSpace (offsetCFrame)
print("Helloo")
end
clickAmount = 0
canClick = false
coal1.Transparency = 1
coal2.Transparency = 1
coal3.Transparency = 1
coal4.Transparency = 1
wait(3)
coal1.Transparency = 0
coal2.Transparency = 0
coal3.Transparency = 0
coal4.Transparency = 0
canClick = true
end
end
click.MouseClick:Connect (addClick)
Script to collect cash:
script.Parent.CanCollide = false
local cloning
db = false
script.Parent.Touched:Connect(function(hit)
cloning = script.Parent:Clone()
script.Parent.Transparency = 0
local humanoid = game.Players:GetPlayerFromCharacter(hit.Parent)
if humanoid then
if not db then
db =true
humanoid.leaderstats.Coins.Value = humanoid.leaderstats.Coins.Value + math.random(10,50)
wait()
for i = 1,1,1 do
script.Parent.Transparency = 1
wait()
print(i)
end
script.Parent:Destroy()
wait(3)
db = false
end
end
end)