#Script won't work. Please help

38 messages · Page 1 of 1 (latest)

storm ingot
#

^ Someone please help

rugged echo
#

just @ dyl

#

he's really good

#

trust

white nacelle
#

is that the name

#

"ActualCoin

#

"

#

and that script is so long for a simple task like that

storm ingot
#

@white nacelle i fixed the code completely

#

it shows no errors when i click play yet still won’t work

white nacelle
#

can i see?

#

@storm ingot

storm ingot
#

So I have a model which is a coin that I've created
in the model it has a ClickDetector
then in the ClickDetector there is a script
that script is

local coinPart = script.Parent
local coinTextLabel = game.Players.LocalPlayer.PlayerGui.CoinsGui.Coins:WaitForChild("ActualCoin")

local clickDetector = coinPart:FindFirstChildOfClass("ClickDetector")
if not clickDetector then
    clickDetector = Instance.new("ClickDetector")
    clickDetector.Parent = coinPart
end

clickDetector.MouseClick:Connect(function(player)
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local coinsValue = leaderstats:FindFirstChild("Coins")
        if coinsValue then
            coinsValue.Value = coinsValue.Value + 5
            coinTextLabel.Text = tostring(coinsValue.Value)
        end
    end
end)

In starterGui
I have a screenGui which I've named coinsGui
in that CoinsGui I have a image label which I've named coins
in that Image label named coins I have another image label which is called OtherCoins (its unimportant its just the coin symbol)
then in the image label named coins again I have a text label called ActualCoin
then I have a localscript called Coins in the ScreenGui
that script is

local coinCountLabel = script.Parent.Coins.ActualCoin
local coinTextLabel = game.Players.LocalPlayer.PlayerGui.CoinsGui.Coins:WaitForChild("ActualCoin")

local function updateCoinCount()
+    local player = game.Players.LocalPlayer
    local coins = player.leaderstats.Coins.Value
    coinCountLabel.Text = tostring(coins)
end

updateCoinCount()

game.Players.PlayerAdded:Connect(function(player)
    player.leaderstats.Coins.Changed:Connect(updateCoinCount)
end)

local function dropCoin()
    local coin = Instance.new("Part")
    coin.Name = "Coin"
    coin.Anchored = true
    coin.CanCollide = false
    coin.Position = Vector3.new(math.random(-50, 50), 10, math.random(-50, 50)) -- Adjust the position range as needed
    coin.Parent = workspace

    local coinText = coinTextLabel:Clone()
    coinText.Parent = coin
    coinText.Visible = true

    coin.Touched:Connect(function(otherPart)
        local player = game.Players.Players.Character
        if player then
            local leaderstats = player:FindFirstChild("leaderstats")
            if leaderstats then
                local coinsValue = leaderstats:FindFirstChild("Coins")
                if coinsValue then
                    coinsValue.Value = coinsValue.Value + 5
                    coin:Destroy()
                end
            end
        end
    end)

    wait(5) -- Adjust the time interval between coin drops as needed

    coin:Destroy()
end

while true do
    dropCoin()
end
#

So when I load up it shows no errors

#

but still wont work for some reason

white nacelle
#

So nothing is happening?

#

Also im abit confused

#

Why is there a + at the start of updateCoins function?

storm ingot
#

but it does nothing

storm ingot
#

oh no i accidently wrote that

#

like in discord

#

mb

#

its not in the script

white nacelle
#

Ok

storm ingot
#

so yeah idk what to do

white nacelle
#

Well

#

Is it local script or script?

white nacelle
#

And last thing: DONT USE CLICKDETECTORS!!

#

Like do this instead

#
local UIS = game:GetService(“UserInputService”).MouseButton1Down:Connect(function(player)
local partHit = player:GetMouse().Target
if partHit.Name == “REPLACE_WITH_NAME_OF_COIN” then
—code to add coins
end
end)
storm ingot
storm ingot