is the code in cash part because you have to make it so if the script parent is touched it would detect the part and other stuff, also replace FindFirstChild with FindFirstChildOfClass.
The code is in cash part. 123 133232
then make it so the local cash = script.Parent
Nothing changed too. (3O characters are so cool)
Then itâs supposed to work if you just detect the touch for the scriptâs parent. The cash parts are cloned and so will the script.
Hold on, First off, I will mention all the problems:
- You need different methods of collecting "Hitâ
- You need a different script method.
Hereâs how you accomplish this:
local part = script.Parent
part.Touched:Connect(function(hit)
local h = hit
if h then
local FindHumanoid = h.Parent:FindFirstChild("Humanoid")
if FindHumanoid then
print("Found Humanoid")
else
warn("It's not a humanoid.")
end
end
end)
This is just an example, this is a method to collect the âhitâ detection of a player. This can hopefully help accomplish what you wanted.
But : This will also not work, put the script in workspace and make a loop, inside of this loop try to find the part in workspace, if itâs found, then the function is found while the game is scanning the script. Hereâs a example:
(Make sure itâs a script)
game.Players.PlayerAdded:Connect(function(player)
while true do
wait(0.5) -- put wait instead of task.wait() so the game can scan other parts of the script.
local Find = game.Workspace:FindFirstChild("CashFolder")
if Find and Find:IsA("BasePart") then
Find.Touched:Connect(function(hit)
-- Then use the rest of the collect touch method.
end
end
end
end)
Now, Things to throw in youâre trash:
Terrible example, He just started coding.
Messy script, teaching him how to make his scriptâs messy, Plus does not work.
And now the rest of the comments:
There just terrible exampleâs. They donât know what they are doing, throw all of those comments in the trash.
Anyways, if you have any questions, Ask me.
Things that you need to know:
- It needsâ to be a script.
- It needs to be in workspace.
- Ask questions if there is problems.
Now here, youâre wrong. The script I provided him works, itâs simple: Once a child is added into the folder, the event is connected to that child. The .Touched event will work for all cash parts except those that were added before the server started running. So hereâs an improved one, I should have thought of that:
local FolderOfCashParts = -- reference here
for _, CashPart in ipairs(FolderOfCashParts:GetChildren()) do
CashPart.Touched:Connect(function(hit)
end)
end
FolderOfCashParts.ChildAdded:Connect(function(child)
child.Touched:Connect(function(hit)
end)
end)
I do agree though that @pumpkyrofl 's code is messy. And this is not me come backing.
Now the script that you just now provided, is not a quite professional solution. Youâre looping through every .5 seconds. This is what happens:
The .Touched
event fires way more times than it should. Ideally it should fire 5-10 times (keep in mind the inaccuracy of the event) but here it fires over 100 times because you connect the event to the part every .5 seconds.
Detecting when the cash part is added into the folder and then connecting the event to that cash part is a way better solution performance and functionality wise.
@TheRealWerinq said that the script is located under the cash part, so heâll just have to do this because when the cash part is cloned, itâs children will also be cloned over to that cloned cash part:
local CashPart = script.Parent
CashPart.Touched:Connect(function(hit)
end)
Down to the points:
Both wrong. The script can be in ServerScriptStorage, not just Workspace. It doesnât need to be a server script as well if @TheRealWerinq would have wanted it to detect the touch locally.
Weâre making everything complicated for this beginner so what you should do is test and do some research before replying. The solutions I provided are working and are far more better than yours.
So in conclusion, just do this:
local CashPart = script.Parent
CashPart.Touched:Connect(function(hit)
end)
I myself would use CollectionService
or store all the cash parts in a folder just to organize everything and keep it more simple. @TheRealWerinq
You dont know that, you have not even tested out my script?
He never said it did, even if it did, he would give you the solution?
Youâre script does not even work.
It still most likely works.
Thatâs not bad? Itâs not like itâs 0.0001.
Wrong, First off, It makeâs it more provick if itâs a script, Second off, It does need to be in workspace, in order to make it loop better.
That wont work.
You dont need to get to the advanced services. Just use my script.
Its not working too⌠1`212121212121
And also your not working.
code i wrote:
local valuetogive = 1
game.Players.PlayerAdded:Connect(function(plr)
while true do
wait(.1)
local find = game.Workspace:FindFirstChild("CashFolder")
if find and find:IsA("BasePart") then
find.Touched:Connect(function(hit)
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player then
print("found a player")
local ls = player.leaderstats
local cash = ls.Cash
cash.Value += valuetogive
end
end)
end
end
end)
And its also in workspace and it is a script.
change find into iffind, find is representing something else, as you can tell, itâs blue.
Make sure your cash parts are always gonna be stored in a folder, then connect the .ChildAdded
event to the folder. Then once the child is added, connect the .Touched
event to that child. Just use the script I provided. Iâm not sure what to say about @Sea_KidTwelve since his script was horrible both performance and functionality wise and it did not even work according to @TheRealWerinq. Yes, mine did not work but it did work for me. There must be an issue on your side.
No result. (3O CHARACTERS OMGMGMGM)
Sorry if we cant help you, if nothing works:
- Use ChatGPT (Not in a bad way, just to learn.)
- Directly message a professional.
alright let me settle this up.
local cash = script.Parent
local checkforhum(child)
if child.Parent:FindFirstChildOfClass("Humanoid") then
return child.Parent
else
checkforhum(child.Parent)
end
repeat task.wait() until cash.Parent == "likethefoldernameorworkspace"
cash.Touched:Connect(function(hit)
local checkers = checkforhum(hit.Parent)
if checkers ~= nil then
local hitplr = game.Players:GetPlayerFromCharacter(checkers)
if hitplr ~= nil then
hitplr:FindFirstChild("leaderstats").Cash.Value += 1
script:Destroy()
end
end)
i have one question, where did you got the child variable?
Finally proved you guys right, please watch this video: Streamable
It is literally the same script I provided earlier and it works correctly. It is definitely something on yallâs side.
And to you, @pumpkyrofl, please do research before posting as youâre a beginner. Youâre not entirely ready to answer questions if youâre a beginner so thatâs why you need to try your script out before providing it. The script you just provided was really messy. Instead, you couldâve just done this:
local Folder = script.Parent:WaitForChild("Folder")
-- We do this because we have parts in the folder that were added before runtime.
for _, part in ipairs(Folder:GetChildren()) do
part.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
print("Touched.")
end
end)
end
Folder.ChildAdded:Connect(function(child)
child.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
print("Touched.")
end
end)
end)
(Same code from the video, btw)
Did i mentioned you guys that the cash part is stores in replicatedstorage? And when i click on an specific part, the cash part spawns in workspace. That means that the cash part is not pre-loaded.