I want this 1 script to make it so that whenever someone touches a part in a certain model, they get cash (so i do not need scripts in each part) This is what I have so far but it does not work.
Bananas = game.Workspace.Bananas:GetChildren() Bananas.Touched:connect(function(hit) local User = game.Players:GetPlayerFromCharacter(hit.Parent) User.Data.Bananas.Value = User.Data.Bananas.Value + 1 end)
How do you always know that it's a player touching it? If you're going to use :GetChildren(), you need to use a for loop!
for i,v in pairs(game.Workspace.Bananas:GetChildren()) do -- The Generic For loop v.Touched:connect(function(hit) -- Touched event if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then -- Checks if it's a player local p = game.Players:GetPlayerFromCharacter(hit.Parent) -- Sets the player variable p.Data.Bananas.Value = p.Data.Bananas.Value + 1 -- Adds 1 to the value! end end) end