how can i do it on serverside not client
and i need to know what i need to do in order to make my script
how can i do it on serverside not client
and i need to know what i need to do in order to make my script
What are you trying to get the magnitude of?
i am trying to get magnitude of the ball to the player so i can prevent firetouchinterest exploits
local Ball = --pathtoyourball
local player = --define your player from remote event or whatever your using to keep record of your players
local distance = player:DistanceFromCharacter(Ball.Position)
EDIT: this takes distance between the ball and the players head’s position and not humanoidrootpart position
how can i calculate the distance between ball and player when ball is touched by player
You can use .Touched events for that
local Ball = script.Parent --or the path to your ball
Ball.Touched:Connect(function(hitpart)
local model = hitpart:FindFirstAncestorOfClass("Model")
local humRp = model:FindFirstChild("HumanoidRootPart")
if model and humRp and game:GetService("Players"):GetPlayerFromCharacter(model) then
local distance = (humRp.Position - Ball.Position).Magnitude
end
end)
…
If the PLAYER and the BALL are TOUCHING, then their distance is 0…
no like it will prevent the player from touching the ball from far away with firetouchinterest
it gives index nil with findfirstchild as error
Try moving the humRp variable inside the if statement
ty for your help but one more question how can i make the player stop touching the ball when magnitude is more than magnitude that i calculated like if magnitude is = 4 when i touched when i touch from far away magnitude is = 5 how can i make it stop touching (sorry for bad english and explanation)
Updated the script a little
local ball = script.Parent
ball.Touched:Connect(function(hit)
local model = hit:FindFirstAncestorOfClass("Model")
local player = game:GetService("Players"):GetPlayerFromCharacter(model)
if model and player then
local humRp = model.PrimaryPart
local distance = (humRp.Position - ball.Position).Magnitude
print(distance)
end
end)
ty i already did that i just have to figure out how to stop player from touching the ball
local Ball = script.Parent --or the path to your ball
Ball.Touched:Connect(function(hitpart)
local model = hitpart:FindFirstAncestorOfClass("Model")
if model and game:GetService("Players"):GetPlayerFromCharacter(model) then
local humRp = model:FindFirstChild("HumanoidRootPart")
local distance = (humRp.Position - Ball.Position).Magnitude
if distance > 5 then
-- need help here
end
end
end)
Log the player or their userid into a table and if the player touches the ball again and the player or player’s userid is present in the table then ignore
i dont want to make player get ignored by the ball i just need to know how to make player stop touching the ball
You could teleport the player a few studs away from the ball, other than that there really isn’t another way to force the player to stop touching it other than ignoring the player
i see thank you for respond ig