Oh i understand what you’re saying now. Can you help me with this I don’t know what i’d do.
What happens if you parent the potion to the character? If you can do that, just parent it and check if it’s a potion by its name
I can parent it but the potions are all named differently should i name them the same name?
They can have different names to help identify them, you have to also parent the parent of the part, part.Parent.Parent = player.Character
Just put those 2 OnServerEvent
in a separate script all on their own in ServerScriptService, and before them, put a table of all the name sof the potions, then loop through the children of t he player’s character, and if their name is in the table, then there’s a potion that you could do stuff with.
If you need more explanation I can try ot help
Uhhh very confused on how to script that and i need more of a explanation
How do i cycle through the children?
Try something like this out
local potionsfolder = --Location of your Potions folder
local names = {}
for _,potion in pairs(potionsfolder:GetChildren()) do
table.insert(names,potion.Name)
end
replicatedstorage.drop.OnServerEvent:Connect(function(player)
if player.Character.HasPotion.Value == true then
local part
for _,name in pairs(names) do
if player.Character:FindFirstChild(name) then
part = player.Character[name]
break
end
end
part.Anchored = false
part.CanCollide = true
part.Parent = workspace
player.Character.HasPotion.Value = false
end
end)
throwpot.OnServerEvent:Connect(function(player, mousehit)
if player.Character.HasPotion.Value == true then
local part
for _,name in pairs(names) do
if player.Character:FindFirstChild(name) then
part = player.Character[name]
break
end
end
part.Anchored = false
part.CanCollide = true
part.Parent = workspace
player.Character.HasPotion.Value = false
part:SetNetworkOwner(player)
part.CFrame = player.Character.Torso.CFrame - player.Character.Torso.CFrame.LookVector *-3
part.Touched:Connect(function(hit)
if hit:IsA("Part") then
if not hit:IsDescendantOf(player.Character) then
print(hit)
part.Anchored = true
local Time = 0.15
local tween = tweenservice:Create(part, TweenInfo.new(Time),{Transparency = 1})
tween:Play()
local fire = game:GetService("ReplicatedStorage").Push:Clone()
fire.Parent = workspace
fire.Position = part.Position
local time_ = 1
local tween1 = tweenservice:Create(fire, TweenInfo.new(time_),{Size = Vector3.new(9,0.025,9)})
tween1:Play()
tween.Completed:Wait()
game:GetService("ServerScriptService").ItemSpawn.Spawned.Value = game:GetService("ServerScriptService").ItemSpawn.Spawned.Value-1
part:Destroy()
tween1.Completed:Wait()
wait(1)
fire:Destroy()
end
end
end)
local bv = Instance.new("BodyVelocity", part)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = player.Character.Torso.CFrame.lookVector*45 + Vector3.new(0,10,0)
local bv1 = Instance.new("BodyVelocity", player.Character["Right Arm"])
bv1.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv1.Velocity = player.Character.Torso.CFrame.lookVector*3 + Vector3.new(0,7,0)
local bv2 = Instance.new("BodyVelocity", player.Character["Torso"])
bv2.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv2.Velocity = Vector3.new(0,-1,0)
wait(0.2)
bv1:Destroy()
bv2:Destroy()
bv:Destroy()
end
end)
Script in ServerSCriptService and remove the OnServerEvent code in the potion scripts
should i do it like this?, if i don’t it gives me a error
local names = {"Fire_Potion","Freeze_Potion","Lightning_Potion","Healing_Potion","Push_Potion"}
You can if you want to, you will have to edit it if you ever add a new potion, although I have a question, is there only a single Meshpart in the potion models?
Then ungroup the parts from the model if there’s only one child and rename to their potion type
What’s wrong with it being in a model?, it’s working fine atm. i’ll give it another test.
i’ve got an error don’t know why
oh i see why you wanted me to make it just the mesh
Yup, and it doens’t make sense to model it when there’s only a single child, ungroup all the potions and rename them to the names of their potion type, make sure you rename them exactly or else it wont detect it
I did, How do i make different potions have different effects?
You will have to connect functions to do something depending on their potion type, you’ll have to make a dictionary containing the name of the potions as a key and a function as a value
local potionfunctions = {
["Fire_Potion"] = function(character)
character.Humanoid.Health = 0
end)
}
To give an example. And to pass in what you want, just reference it and pass it in
potionfunctions["Fire_Potion"](player.Character)
To set your health to 0 for example
Could you give a code example when throwpot is fired?, I’m a little confused.
Something like this for example
local potionsfolder = --Location of your Potions folder
local names = {"Fire_Potion","Freeze_Potion","Lightning_Potion","Healing_Potion","Push_Potion"}
local tweenservice = game:GetService("TweenService")
local potionfunctions = {
["Fire_Potion"] = function(part)
local fire = game:GetService("ReplicatedStorage").Push:Clone()
fire.Parent = workspace
fire.Position = part.Position
local time_ = 1
local tween1 = tweenservice:Create(fire, TweenInfo.new(time_),{Size = Vector3.new(9,0.025,9)})
tween1:Play()
tween.Completed:Wait()
game:GetService("ServerScriptService").ItemSpawn.Spawned.Value -= 1
part:Destroy()
tween1.Completed:Wait()
wait(1)
fire:Destroy()
end)
}
replicatedstorage.drop.OnServerEvent:Connect(function(player)
if player.Character.HasPotion.Value == true then
local part
for _,name in pairs(names) do
if player.Character:FindFirstChild(name) then
part = player.Character[name]
break
end
end
part.Anchored = false
part.CanCollide = true
part.Parent = workspace
player.Character.HasPotion.Value = false
end
end)
throwpot.OnServerEvent:Connect(function(player, mousehit)
if player.Character.HasPotion.Value == true then
local part
for _,name in pairs(names) do
if player.Character:FindFirstChild(name) then
part = player.Character[name]
break
end
end
part.Anchored = false
part.CanCollide = true
part.Parent = workspace
player.Character.HasPotion.Value = false
part:SetNetworkOwner(player)
part.CFrame = player.Character.Torso.CFrame - player.Character.Torso.CFrame.LookVector *-3
part.Touched:Connect(function(hit)
if hit:IsA("Part") then
if not hit:IsDescendantOf(player.Character) then
print(hit)
part.Anchored = true
local Time = 0.15
local tween = tweenservice:Create(part, TweenInfo.new(Time),{Transparency = 1})
tween:Play()
potionfunctions["Fire_Potion"](part)
end
end
end)
local bv = Instance.new("BodyVelocity", part)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = player.Character.Torso.CFrame.lookVector*45 + Vector3.new(0,10,0)
local bv1 = Instance.new("BodyVelocity", player.Character["Right Arm"])
bv1.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv1.Velocity = player.Character.Torso.CFrame.lookVector*3 + Vector3.new(0,7,0)
local bv2 = Instance.new("BodyVelocity", player.Character["Torso"])
bv2.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv2.Velocity = Vector3.new(0,-1,0)
wait(0.2)
bv1:Destroy()
bv2:Destroy()
bv:Destroy()
end
end)
Should work I believe
Does it detect it based off the name?