I am trying to make a script that detects when a part is touched from a local script but it detects every part that a humanoid touches and not a specific part.
The issue is that the part im trying to locate is supposed to be copied once a player does a certain thing, so when the game loads the script spams that it couldn’t find “GS.Portals.Portal1.Hitbox” because when you load in its in replicated storage since it hasn’t been copied yet. How do I make it so it can detect the portal when it is copied into workspace?
Here is the script for the touch script,
local player = game:GetService("Players").LocalPlayer
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local GS = game.Workspace.GameService
local RS = game:GetService("ReplicatedStorage")
local debounce = false
humanoid.Touched:Connect(function(hit)
if hit == GS.Portals.Portal1.Hitbox then
if debounce == true then return end
debounce = true
game:GetService("ReplicatedStorage").Floor2:FireServer()
end
end)
And the remote event script for the copy,
local Player = game:GetService("Players").LocalPlayer
local character = Player.Character
if not character or not character.Parent then
character = Player.CharacterAdded:wait()
end
local Root = character:WaitForChild("HumanoidRootPart")
local GS = game.Workspace.GameService
local TotalButtons = Player:WaitForChild("TotalButtons")
local Portals = game:GetService("ReplicatedStorage"):WaitForChild("Portals")
local RS = game:GetService("ReplicatedStorage")
--Main
TotalButtons.Changed:Connect(function(newValue)
print(newValue)
if newValue >= 8 then
RS.Clone1:FireServer()
elseif newValue >= 16 then
RS.Clone2:FireServer()
elseif newValue >= 24 then
RS.Clone3:FireServer()
end
end)
Every time i run the game the output is spammed with errors and if anyone knows how to fix this please help me out, thank you.