I am trying to make a script detect if the player inside the match and touching the deadly colour/red but most of the times there is a delay. It would be better if it can detect the feet touching the parts but I tried it and usually did not work.
Here is the script used to detect the parts:
local function checkTouchingParts(player)
if not isPlayerInQueue(player) then return end
local character = player.Character
if not character then return end
local root = character:FindFirstChild("HumanoidRootPart")
root.Size = Vector3.new(1.65, 1.8, 1)
if root then
local origin = root.Position
local direction = Vector3.new(0, -3, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local result = workspace:Raycast(origin, direction, raycastParams)
if result and result.Instance then
local touchedPart = result.Instance
if touchedPart.Color == deadlyColor then
if not debounceTable[player] or (os.clock() - debounceTable[player]) >= 1 then
debounceTable[player] = os.clock()
game.Workspace.Speaker1.LifeLost:Play()
lives.Value -= 1
local screenGui = game.Workspace.RoundScreen1.Screen.SurfaceGui.Game
if lives.Value == 4 then
screenGui.Live5.Visible = false
elseif lives.Value == 3 then
screenGui.Live4.Visible = false
elseif lives.Value == 2 then
screenGui.Live3.Visible = false
elseif lives.Value == 1 then
screenGui.Live2.Visible = false
elseif lives.Value == 0 then
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event3 = ReplicatedStorage.TypeText3
local currentPlayers = {script.Parent.CurrentPlayers.Value}
event3:FireAllClients(currentPlayers)
task.spawn(function()
local button = game.Workspace:WaitForChild("Replay1")
button.ClickDetector.MaxActivationDistance = 5
for i = 1, 20 do
button.Color = Color3.fromRGB(26, 255, 0)
task.wait(0.5)
button.Color = Color3.fromRGB(80, 80, 80)
task.wait(0.5)
end
end)
game.Workspace.Speaker1.Lose:Play()
game.Workspace.RoundScreen1.Screen.SurfaceGui.Game.Live1.Visible = false
game.Workspace.Speaker1.Music1:Stop()
game.Workspace.Speaker1.Music2:Stop()
game.Workspace.Speaker1.Music3:Stop()
for _, v in grid:GetDescendants() do
if v:IsA("Model") then
for _, m in v:GetDescendants() do
if m:IsA("BasePart") then
m.Color = Color3.fromRGB(201, 0, 0)
end
end
end
end
end
end
elseif touchedPart.Color == blueColor then
if not debounceTable[player] or (os.clock() - debounceTable[player]) >= 0.2 then
debounceTable[player] = os.clock()
game.Workspace.Speaker1.Collect:Play()
touchedPart.Color = blankColor
touchedPart.Collected.Value = true
end
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
task.spawn(function()
while true do
task.wait()
if started.Value then
checkTouchingParts(player)
end
end
end)
end)
end)
Everything in that function is organized and takes up way less space then just adding a bunch of functions. If you just make a bunch of functions that are copies of this function, it would be a lot harder and longer to read at. It actually wouldnt be easier but instead its harder. I dont even know how adding multiple functions would fix this issue or know whats the problem, I can just use printing to see what it prints out.
Honestly i don’t think raycasts are the way to go, and that you should use humoid.touched instead.
But can you add a print to see if the raycast actually hits anything
Thats what I thought what someone would of said. I tried that and it does not detect it when the player is standing still, the red parts will constantly move
Then attach a part called “Detector” and add a weld constraint to the humanoidrootpart, welding the two together. The detector part should be as wide as the players legs, and long enough to go throught the ground.
You need to use a for loop to check all the tables contents, as GetsPartInPart returns a table. Then do “if v.Name == (the name) then” and then a seperate function does the rest.
Please use functions, they are the backbone of scripting, you NEED them if you want to be able to read your code and bug fix it.
I have fixed the issue by just making a debounce for BOTH red and blue tiles and making the feet detect the tiles instead of just humanoidRootPart. You guys are overcomplicating it and does not help that much. You are saying to change the entire script even though this version worked more better, more efficiently, and just a simple fix in general. And liking the spam topics that has nothing to do with this issue makes you unhelpful.
We just want to give you the best possible feedback, that will help you learn and become a better programmer. In the future, please don’t ask for help if you aren’t willing to even consider other’s advice!!
Your code is messy, unorganised, and is using a system that may not be consistent in the future. It is not our fault if you feel we aren’t helping, because we are.
Advice when people complain about this topic about its “unorganized” and some of you are spamming off topic things? I have told you that the things you have told me does not work and just says why. Using multiple functions is not helpful at all in this topic. If I can understand the code and you can’t, dont yap about saying “erm change it because I dont understand”
And I did consider the advice, but none of it actually helped solve the real issue, which was just needing separate debounces and detecting feet properly, not rewriting everything into multiple functions. The suggestions I got made things more complicated and introduced even more problems, while the original structure worked fine once the actual cause was fixed.
Just because code isn’t structured the way you prefer doesn’t make it messy or wrong. Everyone writes differently, and I structure my code in a way that makes sense to me, and clearly, it works. Giving feedback is great, but assuming it’s the only correct way and ignoring what the actual problem is doesn’t help anyone.
If people want to help, listening and focusing on the real issue is more useful than pushing personal coding styles.