So i have a mannequin, and when player get close to it i want to do some piece of code
and to calculate when player gets close:
1- i will add how mush studes the player needs to be considered close, like 10 or 15 to the XYZ of the mannequin to count the maximum XYZ, and store that
2- i will subtract how mush studes the player needs to be considered close, like 10 or 15 to the XYZ of the mannequin to count the Minimal XYZ, and store that
3- Cheak every certain amount of time if the player XYZ is close, and that will be done by if statment
the player xyz must be bigger then Minimal XYZ and less then maximum XYZ
So i know what to do, but i dont know how xd
i tried to do that by the code down, but i dont think thats how you add/subtract a number to cframe, and i got [Expected identifier when parsing expression, got ‘+=’ ] Error
-- "Man" stands out for Mannequin
local PosMan = script.Parent.HumanoidRootPart.Position
local XforMan = tonumber(PosMan.X)
local YforMan = tonumber(PosMan.Y)
local ZforMan = tonumber(PosMan.Z)
local MaxX = XforMan += 10 -- error at this line
local PlrChar = game.Players.LocalPlayer.Character
local plrrootpart:Part = PlrChar:FindFirstChild("HumanoidRootPart")
while wait(2) do
local PosPlayer = plrrootpart.Position
local XforPlr = tonumber(PosPlayer.X)
local YforPlr = tonumber(PosPlayer.Y)
local ZforPlr = tonumber(PosPlayer.Z)
-- i wanted to put the "if" statment here but i got the error
end
just help me how to add/subtract numbers to cframe and i will do the if statment (:
local mannequin = script.Parent -- Assuming this is the NPC model
local players = game:GetService("Players")
local player = players.LocalPlayer
local runService = game:GetService("RunService")
runService.RenderStepped:Connect(function()
local character = player.Character
if not character then return end
local root = character.PrimaryPart
if not root then return end
local npcPos = mannequin.HumanoidRootPart.Position
local playerPos = root.Position
local magnitude = (npcPos - playerPos).Magnitude
if magnitude < 10 then -- 10 is the radius around the NPC
-- calculate time within radius
end
end)
wait(2)
local DefDesc = workspace.OutfitFolder.DefultHumanoidDescription
local Ammount = 10
local PlrChar = game.Players.LocalPlayer.Character
local plrrootpart:Part = PlrChar:FindFirstChild("HumanoidRootPart")
local PosMan = script.Parent.HumanoidRootPart.Position
local Desc:HumanoidDescription = script.Parent:FindFirstChildOfClass("HumanoidDescription")
local Hum:Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
local XforMan = tonumber(PosMan.X)
local YforMan = tonumber(PosMan.Y)
local ZforMan = tonumber(PosMan.Z)
local MaxX = XforMan + Ammount
local MaxY = YforMan + Ammount
local MaxZ = ZforMan + Ammount
local MinX = XforMan - Ammount
local MinY = YforMan - Ammount
local MinZ = ZforMan - Ammount
while wait(0.1) do
local PosPlayer = plrrootpart.Position
local XforPlr = tonumber(PosPlayer.X)
local YforPlr = tonumber(PosPlayer.Y)
local ZforPlr = tonumber(PosPlayer.Z)
if XforPlr > MinX and YforPlr > MinY and ZforPlr > MinZ and XforPlr < MaxX and YforPlr < MaxY and ZforPlr < MaxZ then
Hum:ApplyDescription(Desc)
else
Hum:ApplyDescription(DefDesc)
end
end
and its working fine (:
but i will try what u send and i will try to understand it to learn
thanks (;