Hey, im trying to make a code that gives a pet when enetered correctly, here is my sctipt that i have so far but it says invokeserver must be called from client, is there away i can do it without having to change all of it to a bindablevent?
local RS = game.ReplicatedStorage
local TS = game:GetService("TweenService")
function rotateEgg(Egg, Rot, NumberTime)
local TI = TweenInfo.new(NumberTime)
local Goal = {CFrame = CFrame.Angles(0,0,math.rad(Rot))}
local Tween = TS:Create(Egg.PrimaryPart, TI, Goal)
Tween:Play()
end
function eggAnimation(plr, Egg, Result)
local FrameClone = plr.PlayerGui.UIelements.HatchFrame:Clone()
local Folder = RS.Pets.Models:FindFirstChild(Result)
local Type
for i,v in pairs(Egg["Pets"]) do
if v.Name == Result then
Type = v.Type
end
end
local PetClone = Folder:FindFirstChild(Type):Clone()
local EggClone = workspace.Eggs:FindFirstChild("EventEgg").EggModel:Clone()
local Rarity = Folder.Settings.Rarity.Value
local RarityColor = RS.Pets.Rarities:FindFirstChild(Rarity).Color.Value
local Camera = Instance.new("Camera", FrameClone)
local tweenInfo = TweenInfo.new(.35, Enum.EasingStyle.Quad)
local EggDelay = .075
game.Lighting.Blur.Size = 26
--script.Parent.Parent.Parent.Parent.Main.Enabled = false
FrameClone.CurrentCamera = Camera
FrameClone.Parent = plr.PlayerGui.EggPreview
EggClone.Parent = FrameClone
EggClone:SetPrimaryPartCFrame(CFrame.new(0,0,0) - Vector3.new(0,10,0))
Camera.CFrame = (EggClone.PrimaryPart.CFrame + Vector3.new(0,10,0)):ToWorldSpace(CFrame.new(0,0,5.5))
local bringEgg = TS:Create(EggClone.PrimaryPart, tweenInfo, {Position = EggClone.PrimaryPart.Position + Vector3.new(0,10,0)})
bringEgg:Play()
wait(.35)
for i = 1,7 do
rotateEgg(EggClone, 15, EggDelay)
wait(EggDelay)
rotateEgg(EggClone, -15, EggDelay)
wait(EggDelay)
EggDelay = EggDelay - .005
end
-- 2.78
rotateEgg(EggClone, 0, EggDelay)
wait(EggDelay)
FrameClone.FlashEffect1:TweenSize(UDim2.new(1.5,0,1.5,2), "Out", "Linear", .2)
spawn(function()
for i = 0,1,.1 do
FrameClone.FlashEffect1.ImageTransparency = i
wait(.05)
end
end)
wait(.2)
PetClone.Parent = FrameClone
PetClone:SetPrimaryPartCFrame(CFrame.new(0,0,0) * CFrame.Angles(0, math.rad(200), 0))
EggClone:Destroy()
FrameClone.PetName1.Text = Result
FrameClone.PetRarity1.Text = Rarity
FrameClone.PetRarity1.TextColor3 = RarityColor
wait(1)
for i = 1,10 do
game.Lighting.Blur.Size = game.Lighting.Blur.Size - 2.6
wait(.05)
end
FrameClone:TweenPosition(UDim2.new(0,0,1,0), "Out", "Quad", .2)
wait(.2)
FrameClone:Destroy()
--script.Parent.Parent.Parent.Parent.Main.Enabled = true
end
function eggRequest(plr, Type, Name)
local Egg = require(RS.Pets.Eggs)[Type]
if Egg ~= nil then
local Result, Message = RS.RemoteEvents.EggOpened:InvokeServer(Type, "Single")
if Message == nil and Result ~= "Error" and Result ~= nil then
eggAnimation(Egg, Result)
else
print("Nope not today")
end
end
end
local function misc(plr, Type, Name)
if not plr or not Type or not Name then return end
eggRequest(plr, Type, Name)
game.ReplicatedStorage.Events.EggNotification:FireClient(plr, "Received " .. Name)
return false
end
return {
["TwitterSpecial"] = function(plr)
misc(plr, "EventEgg", "Ak?n")
end,
}
This is what i get in console:
InvokeServer can only be called from the client script 'ServerStorage.Modules.Codes', Line 75 - function eggRequest script 'ServerStorage.Modules.Codes', Line 121 - function misc script 'ServerStorage.Modules.Codes', Line 177 script 'ServerScriptStorage.MainScript.Codes', Line 27
Thanks Rich
