So im essentially hitting two issues here, neither of which I have been able to resolve, or narrow a source down for.
The first of which is that I have a script to detect a player collision with a child part from a cloned workspace model. The part fires on collision, but it fires several thousand times per second. Ive managed to slow it down to about 100 times per second, but even after a gentle key tap, it still triggers and calls my function upto 15~ times, even with a variable delay (that doesnt seem to be working?)
I just want to be able to collide with the part until the function is triggered, at which case a second function (below) triggers and freezes the players movements (thus denying anymore collision detections), but this doesnt seem to be working as intended and im not sure why.
local repStorage = game:GetService("ReplicatedStorage")
local triggered = repStorage:WaitForChild("TestTrigger")
local lock = true
local function test(body)
if (body.Parent:FindFirstChild("Humanoid")) then
local Player = game.Players:GetPlayerFromCharacter(body.Parent)
local x = math.random(200)
if x > 195 then
triggered:FireClient(Player)
end
end
end
while #_G.loadedRegions > 0 do
wait()
for i = 1, #_G.loadedRegions do
for name, child in pairs(game.Workspace[_G.loadedRegions[i]]:GetChildren()) do
if child.Name == "Loot" and lock == true then
lock = false
child.Touched:connect(test)
wait(1)
lock = true
end
end
end
end
My Second issue is that, while the above function atleast operates the way its supposed to, to a degree. After the first time the player is frozen on a successful run of the math.rand func, the player is continually frozen and unfrozen rapidly by the script, even when not meeting the threshold requirements of the x variable. Once again im not sure whats going down here. Any insights are appreciated
local MasterControl = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("ControlScript"):WaitForChild("MasterControl"))
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local triggered = ReplicatedStorage:WaitForChild("TestTrigger")
local function holding()
MasterControl:Disable()
--GUIFunctions
wait(0.5)
MasterControl:Enable()
end
battleTriggered.OnClientEvent:Connect(holding)
