Hey, so, I would like to pass a sin wave without it being solved on server?
--Server script
local sin = math.sin(tick()*1)*0.11
remoteevent:FireClient(plr, sin)
--Client script
remoteevent.OnClientEvent:Connect(function(sin)
while task.wait() do
print(sin)
end
end)
Let’s say when we fire :FireClient, sin is 0.5.
When it passes on client, it keeps 0.5 on client.
I think this problem occurs because the server script passes 0.5 instead of
What you are looking for is sending a function, however I don’t think you can send functions over events. If you only want this specific function you could just have this stored and, when prompted, calculate it.
-- Server
remoteevent:FireClient(plr, <possible variables>)
remoteevent.OnServerEvent:Connect(function(reply)
if reply == <correct answer> then
-- code for correct answer here
else
-- code for incorrect answer here
end
end)
I don’t think you guys get what im trying to achieve, let me open it more.
I wanna do a fireball projectile moving like a sin value. But since i wanna do the movement on client, I use a remote event.
--Serverscript
local function createFire(pos, sin, sinaxis)
local FireBall = Assets:FindFirstChild("Fireball"):Clone()
local FireBallMain = FireBall:FindFirstChild("Main")
FireBall.Parent = workspace
FireBallMain.Position = Monster.HumanoidRootPart.Position
FireBall.Humanoid.Animator:LoadAnimation(script.Parent.Parent.Animation.Fireball):Play()
for i, Plr in pairs(Players) do
Lighting.AttackRemotes.Undertale.Toriel.FireBall:FireClient(Plr, FireBallMain, sin, sinaxis)
end
end
createFire(nil, math.sin(tick()*1)*0.11, nil)
--Localscript
script.Parent:FindFirstChild("FireBall").OnClientEvent:Connect(function(FireBall, sin, sinaxis)
print("AE")
coroutine.resume(coroutine.create(function()
local times = 0
repeat
times += 1
FireBall.FireBallMain.Position += Vector3.new(0.2, 0, sin)
task.wait()
until times == 500
FireBall:Destroy()
end))
end)
When Im passing the sin formula to the client, it keeps being the same sin value instead of changing through time.
The parameter math.sin(tick()*1)*0.11 will evaluated to a number when the function is called. It is this number which is then eventually sent to the client.
There is no function running creating new numbers, hence why it stays the same.
There are many ways to solve this issue, the way @OceanTubez mentioned being the most intuitive.