So I have a game called Blow Blocks Up! an I have decided to add points into the game. I'm trying to make it so that if someone shoots a rocket at a block they will earn 10 points. Here's my code:
local parent = script.Parent
local player
function onChildTouched(hit)
if hit.name == "Rocket" then
player = hit.creator.Value
game.Players:GetPlayerFromCharacter(workspace[player]).leaderstats.Points.Value = game.Players:GetPlayerFromCharacter(workspace[player]).leaderstats.Points.Value + 10
end
end
-- add a detection for when a child is touched
alright this is my game https://www.roblox.com/games/2850428770/Blow-Blocks-Up-Black-Hole OK i know this script might make it like Destruction Simulator but I still want it anyway.
I've tested this and it works (although I don't have the leaderstats set up on my end)
It iterates through the parts in the model to see is they are parts and if they are parts it connects your function with the touched event.
local parent = script.Parent local player function onChildTouched(hit) if hit and hit.Name == "Rocket" then player = hit.creator.Value game.Players:GetPlayerFromCharacter(workspace[player]).leaderstats.Points.Value = game.Players:GetPlayerFromCharacter(workspace[player]).leaderstats.Points.Value + 10 end end for i,v in pairs(parent:GetChildren()) do if v:IsA("BasePart") then v.Touched:Connect(onChildTouched) end end