#Why the hell is this Touch Event not running

1 messages · Page 1 of 1 (latest)

vagrant marsh
#

local CollectionService = game:GetService("CollectionService")
local cd = false

for _,part in pairs(game.ReplicatedStorage:WaitForChild("RebirthPortals"):GetDescendants()) do
if part:IsA("BasePart") then
CollectionService:AddTag(part,"RebirthPortalTag")
end
end

local function setupPortal(part)
if not part:IsDescendantOf(workspace) then return end
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not cd then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Rebirths.Value += 1
print("this ea")
part.Parent:Destroy()
cd = true
task.delay(5,function()
cd = false
end)
end
end)
end

for _,part in pairs(CollectionService:GetTagged("RebirthPortalTag")) do
setupPortal(part)
end

CollectionService:GetInstanceAddedSignal("RebirthPortalTag"):Connect(function(part)
setupPortal(part)
end)

#

When its in workspace, I toucb it and nun

#

This is in a local script bntw

#

And also, can touch Event fire on client?

graceful blaze
#

i suggest you add print stamps so you can see at which point the code goes bust and then you can narrow down the problem

chilly wind
vagrant marsh
#

Right?

#

Yeha it does

chilly wind
#

Yes. But, since you're adding the tags to the parts inside of replicated storage, and then having it run the setupPortal(), then it will skip everything since they weren't in workspace when it ran.

Unless you're manually having tagged parts in workspace

vagrant marsh
#

I just realized I think thats an outdated one, I made some changes but it still won

#

'won't work

#

1 sec

#

Apologies

#

local script:

 local CollectionService = game:GetService("CollectionService")
local cd = false
local GiveRebirths = game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("GiveRebirths")

for _,part in pairs(game.ReplicatedStorage:WaitForChild("RebirthPortals"):GetDescendants()) do
    if part:IsA("BasePart") then
        CollectionService:AddTag(part,"RebirthPortalTag")
    end
end
CollectionService:GetInstanceAddedSignal("RebirthPortalTag"):Connect(function(part)
    if not part:IsDescendantOf(workspace) then return end
    part.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and not cd then
            GiveRebirths:FireServer()
            print(part.Parent.Parent)
            part.Parent:Destroy()
            cd = true
            task.delay(3,function()
                cd = false
            end)
            local currentRebirthPortal = game.ReplicatedStorage:WaitForChild("RebirthPortals"):FindFirstChild("RebirthPortal"..game.Players.LocalPlayer.leaderstats.Rebirths.Value)
            if currentRebirthPortal then
                local currentRebirthPortalClone = currentRebirthPortal:Clone()
                currentRebirthPortalClone.Parent = workspace
            end
        end
    end)
end)
#
local function setupPortal(part)
    if not part:IsDescendantOf(workspace) then return end
    part.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and not cd then
            GiveRebirths:FireServer()
            print(part.Parent.Parent)
            part.Parent:Destroy()
            cd = true
            task.delay(3,function()
                cd = false
            end)
            ShowPortal()
        end
    end)
end
game.ReplicatedStorage:WaitForChild("RemoteEvents"):FindFirstChild("ShowPortalEventOrTouched").OnClientEvent:Connect(function(data)
    if data == "ShowPortal" then
        ShowPortal()
    end
end)
#

both combined in one, just discord didn't let me send it in one message

chilly wind
#

By the way, where is this local script located

#

Also, the "ShowPortal()" function isn't declared anywhere

vagrant marsh
vagrant marsh
#

1 sec

#

oh no here it is, fuck

#

forgot this was one I sent to my friend before I changed

#

It is very similaer

#

Apologies, genuinely

chilly wind
#

Also, when you're testing this, are you adding a part to workspace and manually adding the tag to it before running the game?

vagrant marsh
#

first part:

local CollectionService = game:GetService("CollectionService")
local cd = false
local GiveRebirths = game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("GiveRebirths")

for _,part in pairs(game.ReplicatedStorage:WaitForChild("RebirthPortals"):GetDescendants()) do
    if part:IsA("BasePart") then
        CollectionService:AddTag(part,"RebirthPortalTag")
    end
end

CollectionService:GetInstanceAddedSignal("RebirthPortalTag"):Connect(function(part)
    if not part:IsDescendantOf(workspace) then return end
    part.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and not cd then
            GiveRebirths:FireServer()
            print(part.Parent.Parent)
            part.Parent:Destroy()
            cd = true
            task.delay(3,function()
                cd = false
            end)
            local currentRebirthPortal = game.ReplicatedStorage:WaitForChild("RebirthPortals"):FindFirstChild("RebirthPortal"..game.Players.LocalPlayer.leaderstats.Rebirths.Value)
            if currentRebirthPortal then
                local currentRebirthPortalClone = currentRebirthPortal:Clone()
                currentRebirthPortalClone.Parent = workspace
            end
        end
    end)
end)
#

second part:

local function ShowPortal()
    local currentRebirthPortal = game.ReplicatedStorage:WaitForChild("RebirthPortals"):FindFirstChild("RebirthPortal"..game.Players.LocalPlayer.leaderstats.Rebirths.Value)
    if currentRebirthPortal then
        local currentRebirthPortalClone = currentRebirthPortal:Clone()
        currentRebirthPortalClone.Parent = workspace
    end
end

local function setupPortal(part)
    if not part:IsDescendantOf(workspace) then return end
    part.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and not cd then
            GiveRebirths:FireServer()
            print(part.Parent.Parent)
            part.Parent:Destroy()
            cd = true
            task.delay(3,function()
                cd = false
            end)
            ShowPortal()
        end
    end)
end


game.ReplicatedStorage:WaitForChild("RemoteEvents"):FindFirstChild("ShowPortalEventOrTouched").OnClientEvent:Connect(function(data)
    if data == "ShowPortal" then
        ShowPortal()
    end
end)
chilly wind
vagrant marsh
tepid kiln
#

where did you fire the "ShowPortalEventOrTouched"? i might be missing it

safe echo
#

Either u messed up the tags somehow, or ur cd doesn’t set back to false

#

Or u used the wrong script in the wrong service