@rtvr56565
here is my map:
If you want to put more locations, only copy the
and rewrite to
elseif randomnumber == 3 then
clone.CFrame = CFrame.new("the position")
and change the
to
local randomnumber = math.Random(1,3)
The script I said to you works in all maps, only you change the CFrame number to the position you want to be the orb(s)
Instead of just scripting and finding the areas that are flat, then spawning the orbs, lets just take the simple route.
Create a folder, and create parts and place them in different areas yourself and just loop through the folder for each part to have an orb randomly spawn in there, here’s an example code:
local function GetOrbs()
local RadWait = math.random(3, 8)
local Folder = -- Your Folder with parts that you're going to have the orbs spawn in
local OrbAreas = Folder:GetChildren() -- Your folder here
local Orb = -- Your orb here
spawn(function()
while true do
for i, v in pairs(Folder:GetChildren()) do
print(i, v.Name)
if #Folder[v.Name]:GetChildren() < 20 then -- How many max orbs you want in each part so it doesn't overfill.
local Area = OrbAreas[math.random(1, #OrbAreas)];
local X = math.random(-Area.Size.x / 2, Area.Size.x / 2);
local Y = math.random(-Area.Size.y / 2, Area.Size.y / 2);
local Z = math.random(-Area.Size.z / 2, Area.Size.z / 2);
local Point = Area.CFrame:ToWorldSpace(CFrame.new(X, Y, Z));
local NewOrb;
NewOrb= Orb:Clone() -- cloning the orb
NewOrb.CFrame = CFrame.new(Point.p)
NewOrb.Parent = Area -- Random area
wait(RadWait)
NewOrb.Touched:connect(function(Grabber)
local PlayerGrabbed = game.Players:GetPlayerFromCharacter(Grabber.Parent);
if PlayerGrabbed ~= nil then
NewOrb:Destroy();
-- Add Orb Speed
end
end)
end
end
end
end)
end
GetOrbs()
yea but im using a proximityprompt here:
local part = script.Parent
local plr = game.Players.LocalPlayer
local stats = plr.leaderstats.XP
if part.Parent == workspace then
local proxprompt = Instance.new("ProximityPrompt")
proxprompt.Parent = script.Parent
proxprompt.KeyboardKeyCode = Enum.KeyCode.E
proxprompt.ActionText = "Pick up"
proxprompt.HoldDuration = 1
proxprompt.Triggered:Connect(function(Plr)
stats.Value = stats.Value + 10
script.Parent:Destroy()
end)
end
@B_rnz it does not work and it says
Script timeout: exhausted allowed execution time - Server - Orbs:8
This script will not work, since Stats need to be updated on the server side in order for changes to be viewed by other players. It’s also not a good idea to let the client change stats, as Exploiters can easily take advantage of this to manipulate them.
Do you mind showing me the entire code?
Also, here’s how you could do it using your proximityPrompts:
Make sure to create spawn parts in the game though, should look like this, which of course you’re going to make invisible:
-- Make sure this is in a script where you're handling the stats, not local script:
local function GetOrbs()
local RadWait = math.random(3, 8)
local Folder = -- Your Folder with parts that you're going to have the orbs spawn in
local OrbAreas = Folder:GetChildren() -- Your folder here
local Orb = -- Your orb here
-- create PromimityPrompt
local proxprompt = Instance.new("ProximityPrompt")
proxprompt.Parent = Orb
proxprompt.KeyboardKeyCode = Enum.KeyCode.E
proxprompt.ActionText = "Pick up"
proxprompt.HoldDuration = 1
spawn(function()
while true do
for i, v in pairs(Folder:GetChildren()) do
print(i, v.Name)
if #Folder[v.Name]:GetChildren() < 20 then -- How many max orbs you want in each part so it doesn't overfill.
local Area = OrbAreas[math.random(1, #OrbAreas)];
local X = math.random(-Area.Size.x / 2, Area.Size.x / 2);
local Y = math.random(-Area.Size.y / 2, Area.Size.y / 2);
local Z = math.random(-Area.Size.z / 2, Area.Size.z / 2);
local Point = Area.CFrame:ToWorldSpace(CFrame.new(X, Y, Z));
local NewOrb;
NewOrb= Orb:Clone() -- cloning the orb
NewOrb.CFrame = CFrame.new(Point.p)
NewOrb.Parent = Area -- Random area
wait(RadWait)
proxprompt.Triggered:Connect(function(Plr)
if Plr ~= nil then
NewOrb:Destroy();
stats.Value = stats.Value + 10
end
end)
end
end
end
end)
end
GetOrbs()
It’s because your Orb Folder doesn’t have any places where the orbs could spawn on inside the folder, try putting some parts around the map:
Like here:
Which should look like here on the map:
The orbs will spawn in those parts you set up manually, so you dont have to worry about orbs spawning inside the terrain.
The difficulty of having to code and make sure that it’s on top of the terrain is difficult, I dont even know if its possible. So setting up the parts around the terrain manually is just significantly easier.
So there should be vector3.new for position and size
while true do
local clone = orb:Clone()
clone.Parent = workspace.orbs
clone.Position = Vector3.new(math.random(-2097.074, 14.905, 798.157, 2883.039, 9.157, -4183.502)
game.workspace.orbs.OrbsValue.Value = game.workspace.orbs.OrbsValue.Value + 1
wait()
if game.Workspace.orbs.OrbsValue.Value >= 100 then
break
end
end
Here, I rewrote the entire code for it to work:
-- script is in ServerScriptService
local function GetOrbs()
local RadWait = math.random(3, 8)
local Folder = -- Your Folder with parts that you're going to have the orbs spawn in
local OrbAreas = Folder:GetChildren() -- Your folder here
local Orb = -- Your orb here
-- create PromimityPrompt
local proxprompt = Instance.new("ProximityPrompt")
spawn(function()
while true do
for i, v in pairs(Folder:GetChildren()) do
print(i, v.Name)
if #Folder[v.Name]:GetChildren() < 20 then -- How many max orbs you want in each part so it doesn't overfill.
local Area = OrbAreas[math.random(1, #OrbAreas)];
local X = math.random(-Area.Size.x / 2, Area.Size.x / 2);
local Y = math.random(-Area.Size.y / 2, Area.Size.y / 2);
local Z = math.random(-Area.Size.z / 2, Area.Size.z / 2);
local Point = Area.CFrame:ToWorldSpace(CFrame.new(X, Y, Z));
wait(RadWait)
local NewOrb;
local NewProx;
NewOrb = Orb:Clone()
NewOrb.CFrame = CFrame.new(Point.p)
NewOrb.Parent = Area
NewProx = proxprompt:Clone()
NewProx.KeyboardKeyCode = Enum.KeyCode.E
NewProx.ActionText = "Pick up"
NewProx.HoldDuration = 1
NewProx.Parent = NewOrb
NewProx.PromptButtonHoldEnded:Connect(function(Plr)
if Plr ~= nil then
NewOrb:Destroy();
stats.Value = stats.Value + 10
print("value given")
end
end)
end
end
end
end)
end
GetOrbs()
robloxapp-20210726-1535226.wmv (4.2 MB) This is the video, showing proof that it works.
ok good because i just finished placing the spawns
wait does it have to be a local script?
It has to be in a script only, you can only change values through scripts
@B_rnz yea but it will give you an error because you can only access the player with a local script and the leaderstats are in the player and there are multiple scripts accessing leaderstats so it will take a while to move it
Heres your solution.
This works without the map being flat.
while true do
wait(math.random(0,100))-- 100 being the maximum amount of time between orbs spawning.
local x=math.random(-100,100)
local z=math.random(-100,100)
local ray=Ray.new(Vector3.new(x,1000,z),Vector3.new(0,-1500,0))
local part,pos=workspace:FindPartOnRay(ray)
local orb=orb:Clone()
orb.Parent=workspace.orbs
orb.Position=pos
workspace.orbs.OrbsValue.Value=workspace.orbs.OrbsValue.Value+1
if workspace.orbs.OrbsValue.Value>=100 then
break
end
end
That’s why you got the player for when the Prox is ended
-- script is in ServerScriptService
local function GetOrbs()
local RadWait = math.random(3, 8)
local Folder = -- Your Folder with parts that you're going to have the orbs spawn in
local OrbAreas = Folder:GetChildren() -- Your folder here
local Orb = -- Your orb here
-- create PromimityPrompt
local proxprompt = Instance.new("ProximityPrompt")
spawn(function()
while true do
for i, v in pairs(Folder:GetChildren()) do
print(i, v.Name)
if #Folder[v.Name]:GetChildren() < 20 then -- How many max orbs you want in each part so it doesn't overfill.
local Area = OrbAreas[math.random(1, #OrbAreas)];
local X = math.random(-Area.Size.x / 2, Area.Size.x / 2);
local Y = math.random(-Area.Size.y / 2, Area.Size.y / 2);
local Z = math.random(-Area.Size.z / 2, Area.Size.z / 2);
local Point = Area.CFrame:ToWorldSpace(CFrame.new(X, Y, Z));
wait(RadWait)
local NewOrb;
local NewProx;
NewOrb = Orb:Clone()
NewOrb.CFrame = CFrame.new(Point.p)
NewOrb.Parent = Area
NewProx = proxprompt:Clone()
NewProx.KeyboardKeyCode = Enum.KeyCode.E
NewProx.ActionText = "Pick up"
NewProx.HoldDuration = 1
NewProx.Parent = NewOrb
NewProx.PromptButtonHoldEnded:Connect(function(Plr)
if Plr ~= nil then
NewOrb:Destroy();
Plr.leaderstats.XP.Value = Plr.leaderstats.XP.Value + 10 -- This should work
print("value given")
end
end)
end
end
end
end)
end
GetOrbs()
Please accept this if it works, it helps potential users in the future, greatly appreciated