I’m trying to get a waving system to work, using https://devforum.roblox.com/t/how-to-get-wave-height-at-a-specific-position/30672/5 , but I ran into a problem. When I tried to call a function, it gave me an error. I tried searching for stuff but really don’t know the cause of this.
local waveHeight = workspace.Terrain.WaterWaveSize * 2;
local waveWidth = 85;
--while _G.GetWaterWaveCycle == nil do wait()
--end
while true do
wait()
if _G.GetWaterWaveCycle ~= nil then
local d = _G.GetWaterWaveCycle()
print(d)
_G.GetWaterWaveCycle()
height(script.Parent.Position.X, script.Parent.Position.Z, d) -- This is the error part!!
end
end
function height(x, z, cycle)
print("Error check")
return waveHeight * math.sin(2*math.pi*x/waveWidth + cycle + math.pi/2)
* math.sin(2*math.pi*z/waveWidth);
end
and the other script:
if not _G.GetWaterWaveCycle then
assert(workspace.Terrain.WaterWaveSpeed==0, "WaveSpeed staat op 0");
local cycleAtLastSet = 0;
local tickAtLastSet = 0;
local speedAtLastSet = 0;
function _G.GetWaterWaveCycle()
return math.pi * 2 * ((cycleAtLastSet + (tick() - tickAtLastSet)
* workspace.Terrain.WaterWaveSpeed / 85) % 1);
end
workspace.Terrain.Changed:connect(function(prop)
if prop == "WaterWaveSpeed" then
cycleAtLastSet = (cycleAtLastSet +
(tick() - tickAtLastSet) * speedAtLastSet / 85) % 1;
print("CYCLE STAAT: ", cycleAtLastSet);
tickAtLastSet = tick();
speedAtLastSet = workspace.Terrain.WaterWaveSpeed;
end
end)
end