I know this is probally really easy to do but I’m really dumb. How do I make it so lets say any player is above 500000 studs. An audio would play only for the player. So like a localscript thing. Would also be nice to have it so I can have multiple audios and it plays a random one.
if i read your post correctly:
Would also be nice to have it so I can have multiple audios and it plays a random one.
you use math.random for this
lets say any player is above 500000 studs. An audio would play only for the player
if i remember i think it has to do with region3?; though you could skip that complicated part if you don’t know about region3, create a invisible part and use that invisible part to use .magnitude on it kinda like: (part.Position - region.Position).magnitude < "number of studs here".
note: remember to search in google; i do see lots of post talking about this however if it’s different to your post well i didn’t read it right then.
you could add a local script and check if humanoidrootpart.Position.Y > 50000 then
play audio
tried this but it didnt work
character = player.Character
hmndrootpart = character:FindFirstChild("HumanoidRootPart")
if hmndrootpart.Position.Y >= 500000 then
workspace.KSP.Playing = true
else
workspace.KSP.Playing = false
end
idk why
it needs to be in a loop, that code will only run once when the game starts, you can put it in a [while true do] loop to make it check continuously instead of just once
while true do
if hmndrootpart.Position.Y >= 500000 then
print(“Above”)
workspace.KSP.Playing = true
else print(“Below”)
workspace.KSP.Playing = false
end
wait(1) – cooldown to prevent the loop from crashing
end
Still wont work
local Position = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
while true do
wait(1)
local songnum = math.random(1,2)
if songnum == 1 and Position.Y >= 500000 then
workspace.KSP.Playing = true
print("ksp")
elseif songnum == 2 and Position.Y >= 500000 then
workspace.ksp2.Playing = true
else
print("Not High Enough")
end
end
Have just tried this
local playerService = game:GetService("Players")
local localPlayer = playerService.LocalPlayer
local playerCharacter = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local pos = playerCharacter.HumanoidRootPart.Position
while true do
wait(1)
local songnum = math.random(1,2)
if songnum == 1 and pos.Y >= 500000 then
workspace.KSP.Playing = true
print("ksp")
elseif songnum == 2 and pos.Y >= 500000 then
workspace.ksp2.Playing = true
else
print("Not High Enough")
end
end
No luck
that is because you defined the postition only once, so the position value will remain the same as when you first sampled it, you need to get the position value inside the loop, so every time it runs. A variable won’t automatically update itself when the value it is sampling is changed.
Here is an example with what @ramdom_player201 stated:
Also I recommend using RenderStepped as it’s better performant wise and you can run code after it unlike a while loop.
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
RunService.RenderStepped:Connect(function()
local CharacterPosition = Character.HumanoidRootPart.Position
if CharacterPosition.Y > 50000 then
print("High enough")
end
end)