I’m just trying to cycle through all the players touching the part and returning any players it finds. I’m not really familiar with OverlapParams but I figured it would be perfect to learn about it for this script.
Basically the script gets a tagged part, finds which tagged part, finds the players on it and then runs the rest. I got many errors and I can’t find any real documentation with other people that did this type of thing. My latest error is…
Here’s what I have so far,
local ButtonConfig = require(game:GetService("ServerScriptService"):FindFirstChild("ButtonConfig"))
local CollectionService = game:GetService("CollectionService")
local taggedParts = CollectionService:GetTagged("TheHitBoxes")
local activeInteractions = {} -- Table to store active button interactions
-- Function to check if the player's parts overlap with the button
local function CheckOverlap(buttonPart, playerParts)
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = {buttonPart} -- Only check for collisions with the button
overlapParams.CollisionGroup = "Default"
local overlappingParts = game.Workspace:GetPartsInPart(buttonPart, overlapParams) -- (Line 47, buttonPart)
local playersTouchingButton = {}
for _, part in ipairs(overlappingParts) do
if CollectionService:HasTag(part, "Player") then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
-- Add the player to the table
table.insert(playersTouchingButton, player)
end
end
end
return playersTouchingButton
end
for _, tp in pairs(taggedParts) do
tp.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player and character:FindFirstChild("Humanoid") then
local buttonName = tp.Parent.Name
local buttonCost = ButtonConfig[buttonName].ButtonCost
local buttonValue = ButtonConfig[buttonName].ButtonValue
local playerstats = player:WaitForChild("playerstats")
local buttonPresses = playerstats:WaitForChild("ButtonPresses")
-- Check if the player is touching the button continuously
local touchingButton = true
local buttonPart = tp -- button part the player is touching
while touchingButton do
local playerParts = character:GetChildren()
local playersTouchingButton = CheckOverlap(buttonPart, playerParts)
for _, touchingPlayer in ipairs(playersTouchingButton) do
if not activeInteractions[touchingPlayer] then
activeInteractions[touchingPlayer] = true
local energy = touchingPlayer.leaderstats.Energy.Value
if energy >= buttonCost then
energy = energy - buttonCost
local playerElement = playerstats:FindFirstChild(buttonName)
if playerElement then
playerElement.Value = playerElement.Value + buttonValue -- Update the appropriate playerstats element
else
warn("Matching playerstats child not found for:", buttonName)
end
buttonPresses.Value = buttonPresses.Value + 1
else
print("Player does not have enough energy")
touchingButton = false
break
end
activeInteractions[touchingPlayer] = nil
end
end
if not touchingButton then
break
end
wait()
end
end
end)
end
I’ve been at this for the better part of 3 days so I came here. This is an extension of my previous query if anyone’s read it.