A local script in the text label
Script inside the local script.
Script in server script service
Change the Touched script to:
for _, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
-- Script
end
end
end
So are you talking about the coins script? Or the 2nd photo when im actually touching it and adding plus 1
The first one, inside the Coins model
It still unfortunately hasnt worked, any ideas?
i was initially thinking it has something to do with the text label?
Can you unfold the two models inside âCoinsâ?
Lol i know, a lot of parts.
The :Connect()
wasnât closed properly. Add a closing bracket right after the 2nd end
Which of the models is the actual coin? Could you show what the âCoinsâ model looks like?
Doesnt work TestyLike3
Pardon me, I meant the first end
.
Ive still got 0 via the GUI
Okay, Iâm just going to take a guess that the âCoinsâ model is the actual coin itself, try this!
local PS = game:GetService("Players")
local coin = script.Parent
for _,v: BasePart in ipairs(coin:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
local model = hit:FindFirstAncestorWhichIsA("Model")
local player = PS:GetPlayerFromCharacter(model)
local coins = player and player.PlayerStats:FindFirstChild("Coins")
if player and coins then
coins.Value += 1
script:Destroy()
else
warn("uh oh")
end
end)
end
end
As you can see the âuh ohâ bit is actually multiplying although it isnt going up in the gui. My question is, is there a problem with the text label, should there be a text button?
Thatâs not good, it means the script cannot find either the player or âplayer.PlayerStats.Coinsâ. Try printing both âplayerâ and âcoinsâ.
Try this instead
local coin = script.Parent
for _,v: BasePart in ipairs(coin:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
Player.PlayerStarts.Coins.Value += 1
script:Destroy()
else
warn("uh oh")
end
end)
end
end
While just relying on âhit.Parentâ works most of the time, there will be cases where an accessory will be detected and not one of the body parts.
I personally use
hit:FindFirstAncestorWhichIsA("Model")
to get the character model, regardless on whether the touched part was a body part or not.