#Script won't work. Please help
38 messages · Page 1 of 1 (latest)
BRO check line 2
is that the name
"ActualCoin
"
and that script is so long for a simple task like that
@white nacelle i fixed the code completely
it shows no errors when i click play yet still won’t work
alr
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
So nothing is happening?
Also im abit confused
Why is there a + at the start of updateCoins function?
basically when I click the coin it's supposed to change the leaderstats coins to 5 more and in the UI also 5 more
but it does nothing
wdym
oh no i accidently wrote that
like in discord
mb
its not in the script
Ok
so yeah idk what to do
Also wouldnt recommend :Clone() a script into the game because for some reason it doesnt work optimally.
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)
i wrote it was a local script
bro thats not gonna do anything
still wont change it