That code isn’t necessary here, it’s not mentioned anywhere in my script.
You said that it’s a model here thought,
But it’s fine I will convert my script so it works for the “destroyer” Part here:
destroying = script.Parent
destroying.Touched:Connect(function(hit)
local Character = hit.Parent
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local player = game:GetService("Players"):GetPlayerFromCharacter(Character)
if Humanoid then
destroying:Destroy()
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5
end
end)
The script above will work just fine, the “givemoney” thing is not necessary here at all.
I would just completely rewrite this script. If this is a tycoon, certain parts should give different amount of money. I would do something like:
destroyPart = script.Parent
destroyPart.Touched:Connect(function(hit)
if hit:FindFirstChild("DropperPart") and hit:IsA("BasePart") then
--Inside the dropper part being dispensed, create a bool value named "DropperPart", so the script knows its the right part.
--Just checking if it doesn't have a humanoid would cause a lot of problems, like destroying a players accessory and other parts in the map.
hit:Destroy()
local moneyToGive = hit:FindFirstChild("MoneyToGive").Value--Inside the DropperPart being dispensed there should be an IntValue named "MoneyToGive" with its value as the amount of cash the player gets.
--This way more expensive droppers give more cash.
local teamColor = destroyPart:FindFirstChild("TeamColor").Value--String Value inside the DestroyPart with the value set as the droppers team.
for i, player in pairs(game.Players:GetPlayers()) do--Works if its a 2 player tycoon too.
if player.Team == teamColor then
player.leaderstats.Money.Value = player.leaderstats.Money.Value + moneyToGive--Gives them the money
end
end
end
end)
Not sure if this would work, havent tested it and there are probably errors that you can fix. Example Photo
edit: Make sure to place the hit:Destroy() after everything is awarded and done, or else the rest of the script wont work.