Touched event not going off

This is our leaderboard script:

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Parent = leaderstats
    cash.Value = 5

    local givemoney = Instance.new("IntValue", game.ServerStorage)
    givemoney.Name = "moneytogive"


end)

destroyer is a part and not a model.

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.

if Humanoid then

that should be

if Humanoid == nil then

He want’s to make it that if a player touches the end of the conveyor it wouldn’t give points. This is the end of a tycoon conveyor.

@ishqpyari Can you send over a file of the model so I can test it and try to get it to work? If you don’t want to I understand.

Can do. I will get my partner to get it for you.

1 Like

-the model was given to C0lvy123, link removed-

Checking in on the progress.

How are you doing? Is it difficult?

1 Like

After trying that script, and a ton of other ideas, we are stumped.

Your script, made it so when the destroyer part was touched, IT got destroyed, instead of the parts that touched it.

1 Like

Hello all! I DID SOME SNOOPING WITH THE SCRIPT AND FIXED IT! THANK YOU EVERYONE FOR ALL YOUR HELP!

1 Like

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.

1 Like