I dont know but i think magnitude it better.
wouldnt that lag for the client though? the loop for the local script. wouldnt both solutions lag the player?
Only for non humanoid object it’s better, I use Player: DistanceFromCharacter() API for character distance checking.
I mean it won’t be an issue as long as there are waits in between the loop and as I said it really depends on the functions that you call from the script.
can one serverscript control all player’s functions that happend if they’re within a certain distance with the lines of code you showed me?
because i had in mind cloning the local script to another player when he comes near the player who has the script already
i mean it wont lag with debounce wouldnt it, if i added the debounce to the script in serverscriptservice
You could have it update a value in the player and have the local script check if it’s true, but then that would require you to fire to server regardless as the server would have to check since the client can be lied to.
Alternatively you could also fire to client and have a localscript listen for the event.
what if i use only one script to control it is it possible
Well considering I don’t know what you’re trying to do but if you’re listening for things from the player when they are close then no you will need a local script to listen for playerinputs, and if it’s only based on just distance alone then you could probably bind it all to the serverscript.
Well im trying to make an infection script does it require one script or more.
im trying to make it so if you stand too close to an infected player you get infected aswell and the script in the serverscriptservice controls that
Short answer yes it can all be controlled in the server script.
Ive got a problem with the debounce now, ive added it to the server script and it isnt printing nor cloning the sound to the player any solutions? so it waits a few seconds before doing it again to avoid lag.
local soundfolder = script.SoundFolder:GetChildren()
local debounce = true
rs.Stepped:Connect(function()
if debounce then
debounce = false
local last = nil
for i,v in pairs(game.Players:GetChildren()) do
if last == nil then
last = v
end
if last.Character and v.Character then
if last and last~= v then
local dist = (last.Character.HumanoidRootPart.Position-v.Character.HumanoidRootPart.Position).magnitude
for i,b in pairs(soundfolder) do
local randomnum = math.random(1,#soundfolder)
if i == randomnum then
local sound = b:Clone()
sound.Parent = last.Character
sound.Volume = 10
sound:Play()
if dist <= 5 then
print("The player "..v.Name.." is close to "..last.Name)
end
last = v
wait()
debounce = true
end
end
end
end
end
end
end)