#Remote event

24 messages · Page 1 of 1 (latest)

queen echo
#

hey, how to make this localscript run in many parts in workspace? the parts will get created sometime in the workspace and i need this to run on them

local clickDetector = script.Parent.ClickDetector
local events = game:GetService("ReplicatedStorage")
local selectTowerEvent = events:WaitForChild("SelectTower")

local function onClicked(player)
    local hrp = script.Parent.Parent.HumanoidRootPart

    if hrp then
        selectTowerEvent:FireServer(player, hrp)
    end
end

clickDetector.MouseClick:Connect(onClicked)```
stuck cloudBOT
#

studio** You are now Level 1! **studio

fossil sentinel
# queen echo hey, how to make this localscript run in many parts in workspace? the parts will...

Well if you create the parts in the same folder you can try

local clickDetector = script.Parent.ClickDetector
local events = game:GetService("ReplicatedStorage")
local selectTowerEvent = events:WaitForChild("SelectTower")

local partsFolder = workspace.partsFolder

partsFolder.ChildAdded:Connect(function(child)
    clickDetector.MouseClick:Connect(function()
        local hrp = script.Parent.Parent.HumanoidRootPart

        if hrp then
            selectTowerEvent:FireServer(player, hrp)
        end
    end)
end)
potent lodge
#

why r u using local scripts if the parts are in workspace

#

wouldnt they not work

queen echo
#

yeah but they do work somewhere else

queen echo
fossil sentinel
stuck cloudBOT
#

studio** You are now Level 4! **studio

queen echo
#
local events = game:GetService("ReplicatedStorage")
local selectTowerEvent = events:WaitForChild("SelectTower")
local towerFolder = workspace.Towers

towerFolder.ChildAdded:Connect(function(child)
    local hitbox = child:WaitForChild("Hitbox")
    if hitbox then
        local clickDetector = hitbox.ClickDetector
        clickDetector.MouseClick:Connect(function()
            local hrp = hitbox.Parent.HumanoidRootPart

            if hrp then
                print("working")
                selectTowerEvent:FireServer(hrp)
            end
        end)
    end
end)
``` welp this didnt work
fossil sentinel
queen echo
fossil sentinel
#

Well uh without more context, I can't help ya script looks fine

queen echo
#

i added this tower in

#

like playing the game

#

wasnt there originally

#

uh wait

fossil sentinel
# queen echo
local events = game:GetService("ReplicatedStorage")
local selectTowerEvent = events:WaitForChild("SelectTower")
local towerFolder = workspace.Towers

towerFolder.ChildAdded:Connect(function(child)
    local hitbox = child.Hitbox
    local clickDetector = hitbox.ClickDetector
    
    clickDetector.MouseClick:Connect(function()
        local hrp = child.HumanoidRootPart or nil
        if hrp == nil then print("No HRP found") return end
        selectTowerEvent:FireServer(hrp)
    end)
end)

Try this I dunno

queen echo
#

hey, it works now

stuck cloudBOT
#

studio** You are now Level 2! **studio

queen echo
#
local towerFolder = workspace:WaitForChild("Towers")

towerFolder.ChildAdded:Connect(function(child)
    local hitbox = child:WaitForChild("Hitbox")
    if hitbox then
        local clickDetector = hitbox.ClickDetector
        clickDetector.MouseClick:Connect(function()
            local hrp = hitbox.Parent.HumanoidRootPart

            if hrp then
                print("working")
            end
        end)
    end
end)
#

just forgot some stuff at the top