Hello!
I am trying to make interactive grass for my Roblox game and I am coming across this glitch:
I have a client and a server script doing different things:
Server: Player Control
local GrassFolder = workspace.Grass
local TS = game:GetService("TweenService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-----|| Settings ||-----
local multiplier = 30 -- 28
local tweentime = .7 -- .8
local cooldown_devision = 8 -- 8
local tweenInfoNormal = TweenInfo.new(tweentime * 2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local tweenInfoTouched = TweenInfo.new(tweentime)
local RandomSize = false
-----| Debounce Dictionary |-----
local CoolDown = {}
for i, grass in ipairs(GrassFolder:GetChildren()) do
if RandomSize then
grass.Size = Vector3.new(math.random(2, 8), grass.Size.Y, math.random(2, 8))
end
grass.HitBox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
CoolDown[grass] = true
local hum = hit.Parent:FindFirstChild("Humanoid")
local movedir = hum.MoveDirection.Unit
if movedir.Magnitude > 0 then
local facevector = grass.RotateMain.CFrame * CFrame.Angles(math.rad(movedir.X * multiplier), math.rad(0), math.rad(movedir.Z * multiplier))
local TweenMove = TS:Create(grass, tweenInfoTouched, {CFrame = facevector})
TweenMove:Play()
wait(tweentime / cooldown_devision)
CoolDown[grass] = false
return
end
CoolDown[grass] = false
end
end)
grass.HitBox.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local hum = hit.Parent:FindFirstChild("Humanoid")
local movedir = hum.MoveDirection.Unit
local facevector = grass.RotateMain.CFrame * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
local TweenNormal = TS:Create(grass, tweenInfoNormal, {CFrame = facevector})
TweenNormal:Play()
end
end)
end
Client: Managing the wind
local TweenService = game:GetService("TweenService")
local tweenInfoTouched = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local GrassFolder = workspace.Grass
local plr = game.Players.LocalPlayer.Name
local character = game.Workspace:WaitForChild(plr)
while wait(0.2) do
local wind = game.Workspace.GlobalWind
local windStrength = wind.Magnitude
if windStrength > 0 then
for i, grass in ipairs(GrassFolder:GetChildren()) do
local d = (grass.Position - character.HumanoidRootPart.Position).magnitude
--wait(0.1)
if d < 50 then -------------------- CHANGE TO PLAYER SETTINGS
------------- IF GRASS IS NOT TOUCHED
local direction = wind.Unit
local radians = math.atan2(direction.Z, direction.X)
local yaw = math.deg(radians) + 180
local random = Random.new()
local final = windStrength / 20
local x = random:NextNumber(2, 3) + final
local z = random:NextNumber(2, 3) + final
local movedir = Vector3.new(x, yaw, z)
local CFrameDifference = grass.RotateMain.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(yaw), math.rad(movedir.Z))
local windtween = TweenService:Create(grass, tweenInfoTouched, {CFrame = CFrameDifference})
windtween:Play()
end
end
end
end
Let me know if you have ideas!