Hi Everyone!
This is my first time using RayCast and i want to make random spawning orb wich gives xp to my pets but it wont work this is my script
This script is in orb and its server-sided
local rayOrigin = script.Parent.Position
local rayDirection = Vector3.new(0, -100, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
local DB = false
local XPgain = 25
local Delay = 5
local randomz = math.random(-22,60)
local randomx = math.random(-58,58)
local ts = game:GetService("TweenService")
local info = TweenInfo.new(0.5)
local goal = {
Size = script.Parent.Size + Vector3.new(1,1,1);
Transparency = 1;
}
local partclone = script.Parent:Clone()
partclone.Script:Destroy()
local tween = ts:Create(partclone,info,goal)
script.Parent.Touched:Connect(function(hit)
local Hum = hit.Parent:FindFirstChild("Humanoid")
if Hum then
if not DB then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
for i,v in pairs(Player.Pets:GetChildren()) do
if v.Equipped.Value == true then
v.TotalXP.Value = v.TotalXP.Value + XPgain
end
end
for i,v in pairs(workspace.PlayerPets:FindFirstChild(Player.Name):GetChildren()) do
spawn(function()
local Clone = game.ReplicatedStorage.Pets.AddXPdisplay:Clone()
Clone.Parent = v.PrimaryPart
for i = 1,25 do
Clone.StudsOffset = Clone.StudsOffset + Vector3.new(0, .04, 0)
Clone.TextLabel.TextTransparency = Clone.TextLabel.TextTransparency + .04
wait(.02)
end
Clone:Destroy()
end)
end
DB = true
tween:Play()
if raycastResult then
local hitPart = raycastResult.Instance
script.Parent.Position = Vector3.new(randomx,hitPart.Position.Y + Vector3.new(0,3,0),randomz)
end
script.Parent.Transparency = 1
wait(Delay)
DB = false
partclone:Destroy()
script.Parent.Transparency = 0
end
end
end)
Any Help is appreciated Thanks!