Two Codes Confliting each other, how to fix it? - lua

I made 2 codes of special abilitys and if i activate the SuperFireSphere code, then the Combat code damage stop working, the hitbox don't spawn in workspace and i don't know how to fix it.
SuperFireSphere Code:
local ts = game:GetService("TweenService")
local replicated = game.ReplicatedStorage
local onepiecepowers = replicated.OnePiecePowers
local Info = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local ss = game:GetService("ServerStorage")
local FireWind = ss.FireWind:Clone()
local db = true
onepiecepowers.AceGiantFire.OnServerEvent:Connect(function(Player, Hit)
local char = Player.Character or Player.CharacterAdded:Wait()
local SuperFireSphere = Instance.new("Part")
local hrpp = char.PrimaryPart
local currentcam = workspace.Camera
currentcam.CameraSubject = char.Humanoid
currentcam.CameraType = Enum.CameraType.Scriptable
SuperFireSphere.Shape = Enum.PartType.Ball
SuperFireSphere.Material = Enum.Material.Neon
SuperFireSphere.BrickColor = BrickColor.new("New Yeller")
SuperFireSphere.Anchored = true
SuperFireSphere.CanCollide = false
task.wait(.2)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = CFrame.lookAt(hrpp.CFrame.Position, Hit.Position).LookVector * 150
hrpp.Position += Vector3.new(0, 50 , 0)
hrpp.Anchored = true
SuperFireSphere.Parent = workspace
FireWind:SetPrimaryPartCFrame(hrpp.CFrame)
FireWind.Parent = workspace
SuperFireSphere.Position = char.PrimaryPart.Position + Vector3.new(0,15,0)
for i = 1, 15 do
task.wait(.1)
SuperFireSphere.Size += Vector3.new(2,2,2)
end
for i, parts in pairs(FireWind:GetDescendants()) do
if parts:IsA("MeshPart") then
local tween = ts:Create(parts, Info, {Transparency = 1})
tween:Play()
end
end
local connect = SuperFireSphere.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= char.Humanoid and db == true then
db = false
hit.Parent.Humanoid.Health -= char.DevilFruitPoints.Value
task.wait(2)
db = true
end
end)
local FireParticle = ss.Fire:Clone()
FireParticle.Parent = SuperFireSphere
SuperFireSphere.Anchored = false
bv.Parent = SuperFireSphere
task.wait(2)
hrpp.Anchored = false
FireWind.Parent = ss
for i, parts in pairs(FireWind:GetDescendants()) do
if parts:IsA("MeshPart") then
parts.Transparency = 0
end
end
task.wait(5)
SuperFireSphere:Destroy()
connect:Disconnect()
end)
Combat:
local replicated = game:GetService("ReplicatedStorage")
local combatevent = replicated.Combat
local servstore = game:GetService("ServerStorage")
local runservice = game:GetService("RunService")
local db = true
combatevent.OnServerEvent:Connect(function(Player)
local char = Player.Character or Player.CharacterAdded:Wait()
local hbox = Instance.new("Part")
hbox.Size = Vector3.new(1.5,1.5,1.5)
hbox.Anchored = true
hbox.CanCollide = false
local connection = runservice.Heartbeat:Connect(function(dt)
hbox.Position = char.RightHand.Position
end)
local tconnection = hbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= char.Humanoid and db then
db = false
hit.Parent.Humanoid.Health -= char.Strenght.Value
task.wait(.1)
db = true
end
end)
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://10497535355"
animation.Parent = char.Humanoid
local loadanim = char.Humanoid:LoadAnimation(animation)
loadanim:Play()
hbox.BrickColor = BrickColor.new("Really red")
hbox.Transparency = 0.5
hbox.Name = Player.Name
print(hbox.Name)
task.wait(.2)
hbox:Destroy()
tconnection:Disconnect()
loadanim:Stop()
connection:Disconnect()
end)
Does someone have any suggestion to help me to fix that??
.........................................................

Related

How i can make the parts of a Model be together with primarypart and follow it

I want to make a vfx model primary part go to the Player Character Primary Part, but the parts of the vfx model isn't moving with the model primary part. I tried to weld them but didnt work. What can i do? Code below:
local replicated = game.ReplicatedStorage
local powers = replicated.Powers
local ss = game.ServerStorage
local FireWind = ss.FireWind:Clone()
powers.GiantFire.OnServerEvent:Connect(function(Player, Hit)
local char = Player.Character or Player.CharacterAdded:Wait()
local hrpp = char.PrimaryPart
local SuperFireSphere = Instance.new("Part")
SuperFireSphere.Shape = Enum.PartType.Ball
SuperFireSphere.Material = Enum.Material.Neon
SuperFireSphere.BrickColor = BrickColor.new("New Yeller")
SuperFireSphere.Anchored = true
SuperFireSphere.CanCollide = false
task.wait(.2)
hrpp.Position += Vector3.new(0, 50 , 0)
hrpp.Anchored = true
SuperFireSphere.Parent = workspace
FireWind.PrimaryPart.Position = hrpp.Position
FireWind.Parent = workspace
SuperFireSphere.Position = char.PrimaryPart.Position + Vector3.new(0,15,0)
for i = 1, 10 do
task.wait(.1)
SuperFireSphere.Size += Vector3.new(2,2,2)
end
task.wait(10)
SuperFireSphere:Destroy()
hrpp.Anchored = false
end)
You should try set the PrimaryPartCFrame using model:SetPrimaryPartCFrame(cframe)
In this case, you want it to follow the HumanoidRootPart CFrame.
local model = workspace.Model
local char = game.Players.LocalPlayer:WaitForChild('Character')
local hrp = char.HumanoidRootPart
local part = workspace.Part
model:SetPrimaryPartCFrame(hrp.CFrame) -- sets the model's primary part's CFrame to the hrp.
Local potato = 10
Local TestAmount = 11
If potato == 10 then
Script.parent.cancollide = false
End
If TestAmount == 11 then
Script.parent.transparency = false
end

How to make a code that shakes the camera of the player

I tried to make a code that's shake the camera player when a RemoteEvent is fired by a key on the keyboard. But it didn't worked. I tried to use the CameraOffset but didn't worked too. How can i make this code without using the CameraShakeModule??? Any sugestion??? Code below:
local ts = game:GetService("TweenService")
local replicated = game.ReplicatedStorage
local powers = replicated.Powers
local Info = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local ss = game:GetService("ServerStorage")
local FireWind = ss.FireWind:Clone()
powers.GiantFire.OnServerEvent:Connect(function(Player, Hit)
local char = Player.Character or Player.CharacterAdded:Wait()
local SuperFireSphere = Instance.new("Part")
local hrpp = char.PrimaryPart
local currentcam = workspace.Camera
currentcam.CameraSubject = char.Humanoid
currentcam.CameraType = Enum.CameraType.Scriptable
SuperFireSphere.Shape = Enum.PartType.Ball
SuperFireSphere.Material = Enum.Material.Neon
SuperFireSphere.BrickColor = BrickColor.new("New Yeller")
SuperFireSphere.Anchored = true
SuperFireSphere.CanCollide = false
task.wait(.2)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = CFrame.lookAt(hrpp.CFrame.Position, Hit.Position).LookVector * 150
hrpp.Position += Vector3.new(0, 50 , 0)
hrpp.Anchored = true
SuperFireSphere.Parent = workspace
FireWind:SetPrimaryPartCFrame(hrpp.CFrame)
FireWind.Parent = workspace
SuperFireSphere.Position = char.PrimaryPart.Position + Vector3.new(0,15,0)
for i = 1, 15 do
task.wait(.1)
SuperFireSphere.Size += Vector3.new(2,2,2)
end
for i, parts in pairs(FireWind:GetDescendants()) do
if parts:IsA("MeshPart") then
local tween = ts:Create(parts, Info, {Transparency = 1})
tween:Play()
end
end
for i = 1,20 do
local x = math.random(-100, 100)/100
local y = math.random(-100, 100)/100
local z = math.random(-100, 100)/100
char.Humanoid.CameraOffset = Vector3.new(x,y,z)
print(i)
task.wait(.5)
end
local FireParticle = ss.Fire:Clone()
FireParticle.Parent = SuperFireSphere
SuperFireSphere.Anchored = false
bv.Parent = SuperFireSphere
task.wait(2)
hrpp.Anchored = false
FireWind.Parent = ss
for i, parts in pairs(FireWind:GetDescendants()) do
if parts:IsA("MeshPart") then
parts.Transparency = 0
end
end
task.wait(5)
SuperFireSphere:Destroy()
end)
Your problem is that you made the CameraType scriptable, with it scriptable, the character's Humanoid no longer has control of it. Remove the lines that make the CameraType scriptable and it will solve your issue.

Argument 1 missing or nil error on roblox studio

Hope you are having a good day. I am just here to say I have watched Alvinblox's egg hatching system tutorial and I am currently at part 2. There is a new error called "Argument 1 missing or nil" it is at line 60 in the petFollowPlayer script (local pet = game.ReplicatedStorage.HatchablePets:FindFirstChild(petName)) here is the code
petFollowPlayer
local function equipPet(player, pet, petName)
print(player)
local character = player.Character
if pet ~= nil and character ~= nil then
if character:FindFirstChild(player.Name.."s' pet") then
character(player.Name.."s' pet"):Destroy()
end
if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
end
pet.Name = player.Name.."'s pet"
pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
local modelSize = pet.PrimaryPart.Size
local attachmentCharacter = Instance.new("Attachment")
attachmentCharacter.Visible = false
attachmentCharacter.Parent = character.HumanoidRootPart
attachmentCharacter.Position = Vector3.new(-1,0,1) + modelSize
attachmentCharacter.Name = "attachmentCharacter"
local attachmentPet = Instance.new("Attachment")
attachmentPet.Parent = pet.PrimaryPart
local alignPosition = Instance.new("AlignPosition")
alignPosition.MaxForce = 25000
alignPosition.Attachment0 = attachmentPet
alignPosition.Attachment1 = attachmentCharacter
alignPosition.Responsiveness = 25
alignPosition.Parent = pet
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.MaxTorque = 25000
alignOrientation.Attachment0= attachmentPet
alignOrientation.Attachment1= attachmentCharacter
alignOrientation.Responsiveness = 25
alignOrientation.Parent = pet
pet.Parent = character
end
end
game.Players.PlayerAdded:Connect(function(player)
local equipedPet = Instance.new("StringValue")
equipedPet.Name = "EquipedPet"
equipedPet.Parent = player
equipedPet.Value = ""
player.CharacterAdded:Connect(function(char)
if game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value) then
local clone =game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value):Clone()
equipPet(player,clone)
end
end)
equipedPet.Changed:Connect(function ()
if equipedPet.Value ~= nil then
if game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value) then
equipPet(player, game.ReplicatedStorage:WaitForChild("HatchablePets"):FindFirstChild(equipedPet.Value):Clone())
end
end
end)
end)
game.ReplicatedStorage.equipPet.OnServerEvent:Connect(function(player,petName)
local pet = game.ReplicatedStorage.HatchablePets:FindFirstChild(petName)
if pet and player.PetInventory:FindFirstChild(petName) then
player.EquipedPet.Value = petName
end
end)
game.ReplicatedStorage.unequipPet.OnServerEvent:Connect(function(player)
player.EquippedPet.Value = ""
if player.Character:FindFirstChild(player.Name.."'s name") then
player.Character[player.Name.."'s pet"]:Destroy()
end
if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
end
end)
buyBasicEgg
local cost = 50
local petMoudle = require(game.ServerScriptService.BasicEggModule)
local prompt = workspace["Egg Holder"].Part.ProximityPrompt
prompt.Triggered:Connect(function (player)
if player.leaderstats.Cash.Value >= cost then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
local pet = petMoudle.chooseRandomPet()
local petval = Instance.new("StringValue")
petval.Name = pet.Name
petval.Parent = player.PetInventory
print(pet.Name.." selected")
game.ReplicatedStorage.HatchEgg:FireClient(player, pet)
end
end)
basicEggAnimation
local camera = workspace.Camera
local studio = workspace.Studio
local template = script.Parent.Pets.ScrollingFrame.Template
local scrollingFrame = script.Parent.Pets.ScrollingFrame
local buttonConnection = {}
local function setTemplateEquipped()
for i,v in pairs(scrollingFrame:GetChildren()) do
if v:FindFirstChild("Equipped") then
v.Equipped.Text = "UNEQUIPPED"
v.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
end
end
template.Equiped.Text = "Equipped"
template.Equiped.TextColor3 = Color3.fromRGB(0,255,0)
end
local function addToFrame(pet)
local newTemplate = template:Clone()
newTemplate.Name = pet.Name
newTemplate.petName.Text = pet.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
local camera = Instance.new("Camera")
local newPet = pet:Clone()
newPet.Parent = newTemplate.ViewportFrame
camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.LookVector * 3), newPet.PrimaryPart.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
buttonConnection[#buttonConnection+1] = newTemplate.MouseButton1Click:Connect(function()
if newTemplate.Equiped.Text == "EQUIPPED" then
game.ReplicatedStorage.unequipPet:FireServer(pet.Name)
newTemplate.Equiped.Text = "UNEQUIPPED"
newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
else
game.ReplicatedStorage.equipPet:FireServer()
setTemplateEquipped(newTemplate)
end
end)
end
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function (pet)
addToFrame(pet)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = studio.CameraPart.CFrame
wait(1.5)
for i = 1,50,1 do
studio["Egg Mesh"].Size = studio["Egg Mesh"].Size + Vector3.new(0.1,0.1,0.1)
wait(0.01)
end
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.BlastPressure = 0
explosion.Position = studio["Egg Mesh"].Position
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.DestroyJointRadiusPercent = 0
explosion.Parent = studio["Egg Mesh"]
studio["Egg Mesh"].Transparency = 1
local petClone = pet:Clone()
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
end
end
petClone:SetPrimaryPartCFrame(CFrame.new(studio["Egg Mesh"].Position, studio.CameraPart.Position))
petClone.Parent = studio
petClone.PrimaryPart.Position = Vector3.new(-14.382, -8.112, -605.565)
petClone.PrimaryPart.Anchored = true
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
0,
false,
0
)
local TweenService = game:GetService("TweenService")
local targetVector = petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)
local lookVector = petClone.PrimaryPart.Position
local targetCframe = CFrame.new(targetVector, lookVector)
local propsToTween = { CFrame = targetCframe }
local tween = TweenService:Create(camera, tweenInfo, propsToTween)
tween:Play()
wait(5)
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
camera.CameraType = Enum.CameraType.Custom
studio["Egg Mesh"].Transparency = 0
studio["Egg Mesh"].Size = Vector3.new(4.732, 6, 4.732)
petClone:Destroy()
end)
If you can help thank you so much it will be very appreciated :)
Looking at the line local pet = game.ReplicatedStorage.HatchablePets:FindFirstChild(petName)
The error is telling you that, for some reason, petName isn't defined. So looking at how the variable is defined, we need to check how game.ReplicatedStorage.equipPet is called. So looking in the addToFrame local function, you call it like this : game.ReplicatedStorage.equipPet:FireServer(). Your problem is that you haven't provided the pet name at all. So just do the same thing you did with the unequipPet event.
buttonConnection[#buttonConnection+1] = newTemplate.MouseButton1Click:Connect(function()
if newTemplate.Equiped.Text == "EQUIPPED" then
game.ReplicatedStorage.unequipPet:FireServer(pet.Name)
newTemplate.Equiped.Text = "UNEQUIPPED"
newTemplate.Equiped.TextColor3 = Color3.fromRGB(255,0,0)
else
game.ReplicatedStorage.equipPet:FireServer(pet.Name)
setTemplateEquipped(newTemplate)
end
end)

There is an error "Positon is not a valid member of Part "Workspace.Studio.Mouse.hitbox" which is strange

I have watched Alvinblox's egg hatching tutorial and once again there is an error :/
the error is "Positon is not a valid member of Part "Workspace.Studio.Mouse.hitbox""
Here is the code below if you can help me thank you so much!
local camera = workspace.Camera
local studio = workspace.Studio
local template = script.Parent.Pets.ScrollingFrame.Template
local scrollingFrame = script.Parent.Pets.ScrollingFrame
local function addToFrame(pet)
local newTemplate = template:Clone()
newTemplate.Name = pet.Name
newTemplate.petName.Text = pet.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
local camera = Instance.new("Camera")
local newPet = pet:Clone()
newPet.Parent = newTemplate.ViewportFrame
camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.LookVector * 3), newPet.PrimaryPart.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
end
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function (pet)
addToFrame(pet)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = studio.CameraPart.CFrame
wait(1.5)
for i = 1,50,1 do
studio["Egg Mesh"].Size = studio["Egg Mesh"].Size + Vector3.new(0.1,0.1,0.1)
wait(0.01)
end
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.BlastPressure = 0
explosion.Position = studio["Egg Mesh"].Position
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.DestroyJointRadiusPercent = 0
explosion.Parent = studio["Egg Mesh"]
studio["Egg Mesh"].Transparency = 1
local petClone = pet:Clone()
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
end
end
petClone:SetPrimaryPartCFrame(CFrame.new(studio["Egg Mesh"].Position, studio.CameraPart.Position))
petClone.Parent = studio
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = game:GetService("TweenService"):Create(camera, TweenInfo, {CFrame = CFrame.new(petClone.PrimaryPart.Positon + (petClone.PrimaryPart.CFrame.lookVector * 5)+Vector3.new(0,0.75,0)),petClone.PrimaryPart.Position})
tween:Play()
wait(5)
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
camera.CameraType = Enum.CameraType.Custom
studio["Egg Mesh"].Transparency = 0
studio["Egg Mesh"].Size = Vector3.new(4.732, 6, 4.732)
end)
Here is the fireserver code
local cost = 50
local petMoudle = require(game.ServerScriptService.BasicEggModule)
local prompt = workspace["Egg Holder"].Part.ProximityPrompt
prompt.Triggered:Connect(function (player)
if player.leaderstats.Cash.Value >= cost then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
local pet = petMoudle.chooseRandomPet()
print(pet.Name.." selected")
game.ReplicatedStorage.HatchEgg:FireClient(player, pet)
end
end)
Here is the module
local petMoudle = {}
petMoudle.Pets = {
["Legendary"] = {
game.ReplicatedStorage.HatchablePets["lil' demon"];
};
["Rare"] = {
game.ReplicatedStorage.HatchablePets["Ice golem"];
game.ReplicatedStorage.HatchablePets["Light Bat"];
};
["Uncommon"] = {
game.ReplicatedStorage.HatchablePets.Fox
};
["Common"] = {
game.ReplicatedStorage.HatchablePets.Bunny;
game.ReplicatedStorage.HatchablePets.Mouse
}
}
petMoudle.rarities = {
["Legendary"] = 5;
["Rare"] = 15;
["Uncommon"] = 30;
["Common"] = 50
}
petMoudle.chooseRandomPet = function()
local randomNumber = math.random(1, 100)
local counter = 0
for rarity, weight in pairs(petMoudle.rarities) do
counter = counter + weight
if randomNumber <= counter then
local rarityTable = petMoudle.Pets[rarity]
local chosenPet = rarityTable[math.random(1, #rarityTable)]
return chosenPet
end
end
end
return petMoudle
Once again thank you if you can help me

Unable to cast to Dictionary error on lua

I have watched Alvinblox's egg hatching tutorial and FOR THE 3RD TIME there is an error :/
the error is "Unable to cast to Dictionary" It is at line 53 (the longest line)
Here is the code below if you can help me thank you so much!
local camera = workspace.Camera
local studio = workspace.Studio
local template = script.Parent.Pets.ScrollingFrame.Template
local scrollingFrame = script.Parent.Pets.ScrollingFrame
local function addToFrame(pet)
local newTemplate = template:Clone()
newTemplate.Name = pet.Name
newTemplate.petName.Text = pet.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
local camera = Instance.new("Camera")
local newPet = pet:Clone()
newPet.Parent = newTemplate.ViewportFrame
camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.LookVector * 3), newPet.PrimaryPart.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
end
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function (pet)
addToFrame(pet)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = studio.CameraPart.CFrame
wait(1.5)
for i = 1,50,1 do
studio["Egg Mesh"].Size = studio["Egg Mesh"].Size + Vector3.new(0.1,0.1,0.1)
wait(0.01)
end
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.BlastPressure = 0
explosion.Position = studio["Egg Mesh"].Position
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.DestroyJointRadiusPercent = 0
explosion.Parent = studio["Egg Mesh"]
studio["Egg Mesh"].Transparency = 1
local petClone = pet:Clone()
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
end
end
petClone:SetPrimaryPartCFrame(CFrame.new(studio["Egg Mesh"].Position, studio.CameraPart.Position))
petClone.Parent = studio
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = game:GetService("TweenService"):Create(camera, TweenInfo, {CFrame = CFrame.new(petClone.PrimaryPart.Positon + (petClone.PrimaryPart.CFrame.lookVector * 5)+Vector3.new(0,0.75,0)),petClone.PrimaryPart.Position})
tween:Play()
wait(5)
for i,v in pairs(petClone:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
camera.CameraType = Enum.CameraType.Custom
studio["Egg Mesh"].Transparency = 0
studio["Egg Mesh"].Size = Vector3.new(4.732, 6, 4.732)
end)
Here is the fireserver code
local cost = 50
local petMoudle = require(game.ServerScriptService.BasicEggModule)
local prompt = workspace["Egg Holder"].Part.ProximityPrompt
prompt.Triggered:Connect(function (player)
if player.leaderstats.Cash.Value >= cost then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
local pet = petMoudle.chooseRandomPet()
print(pet.Name.." selected")
game.ReplicatedStorage.HatchEgg:FireClient(player, pet)
end
end)
Here is the module
local petMoudle = {}
petMoudle.Pets = {
["Legendary"] = {
game.ReplicatedStorage.HatchablePets["lil' demon"];
};
["Rare"] = {
game.ReplicatedStorage.HatchablePets["Ice golem"];
game.ReplicatedStorage.HatchablePets["Light Bat"];
};
["Uncommon"] = {
game.ReplicatedStorage.HatchablePets.Fox
};
["Common"] = {
game.ReplicatedStorage.HatchablePets.Bunny;
game.ReplicatedStorage.HatchablePets.Mouse
}
}
petMoudle.rarities = {
["Legendary"] = 5;
["Rare"] = 15;
["Uncommon"] = 30;
["Common"] = 50
}
petMoudle.chooseRandomPet = function()
local randomNumber = math.random(1, 100)
local counter = 0
for rarity, weight in pairs(petMoudle.rarities) do
counter = counter + weight
if randomNumber <= counter then
local rarityTable = petMoudle.Pets[rarity]
local chosenPet = rarityTable[math.random(1, #rarityTable)]
return chosenPet
end
end
end
return petMoudle
Once again thank you if you can help me
The TweenService:Create function expects a dictionary for the last argument, and you have provided this (simplified):
{ CFrame = CFrame.new(...), petClone.PrimaryPart.Position }
The error you are getting is telling you that the table you have created has mixed keys, and that cannot be cast to just a dictionary. But all of this is because your actual issue was a misplaced close parenthesis. It's supposed to be...
CFrame.new(..., petClone.PrimaryPart.Position)
Now, let's fix it and break up this line into more readable parts...
local TweenService = game:GetService("TweenService")
local targetVector = petClone.PrimaryPart.Positon + (petClone.PrimaryPart.CFrame.lookVector * 5) + Vector3.new(0,0.75,0)
local lookVector = petClone.PrimaryPart.Position
local targetCframe = CFrame.new(targetVector, lookVector)
local propsToTween = { CFrame = targetCframe }
local tween = TweenService:Create(camera, tweenInfo, propsToTween)
tween:Play()

Resources