You are connecting the same Touched events every 1/10 of a second. This is very inefficient code.
Is every grass a model?
You are connecting the same Touched events every 1/10 of a second. This is very inefficient code.
Is every grass a model?
yes they are models. but the grass model has like 20 stands from grass in it
You canât tween models just by tweening the primarypart there is something else to do.
Here is a method:
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new()
local function tweenModel(model, CF)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = model:GetPivot()
CFrameValue:GetPropertyChangedSignal("Value"):connect(function()
model:PivotTo(CFrameValue.Value)
end)
local tween = tweenService:Create(CFrameValue, info, {Value = CF})
tween:Play()
tween.Completed:connect(function()
CFrameValue:Destroy()
end)
end
ok, i will try it, but how would i test this do i just put this in the model or?
tweenModel(grassModel, tweenInfo, CFrame)
wait but that would not work there is no touched event
Itâs a METHOD to tween the model⌠You put it in the touched event.
ooh ok, thanks! sorry sometimes my brain doesnât process things lol
I donât know why but i am really struggling to figure this out, everything I try to do to make it work doesnât work I donât know what I am doing wrong. The whole script is a mess now lol
hey! so I have been trying to use this guyâs script to try and implement it into mine because I have no other idea on how to do it myself. I was wondering if you could walk me through the script so i could understand it better and maybe try using it to make my plants shake. I found this guys when searching and he is trying to do the same thing as me
i want to try and understand this version of the script
local grassfolder = workspace.Grass
local Players = game:GetService(âPlayersâ)
local ts = game:GetService(âTweenServiceâ)
for i, grass in pairs(grassfolder:GetChildren()) do
local CharModel = hit:FindFirstAncestorWhichIsA(âAccesoryâ)
grass.HitBox.Touched:Connect(function(hit)
if Players:GetPlayerFromCharacter(CharModel) then
local hum = CharModel:FindFirstChild("Humanoid")
local movedir = hum.MoveDirection.Unit
local facevector = grass.PrimaryPart.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Z))
local tween = ts:Create(grass.PrimaryPart, TweenInfo(.5), {CFrame = grass.PrimaryPart.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Y))})
tween:Play()
end
end)
end
To make plants tween in the direction the player is walking, you will need to use some scripting. You will need to create a script that will detect the playerâs direction and then use a tweening library to move the plants in the same direction.
The code would look something like this:
// Get the playerâs direction
Vector2 direction = playerObject.transform.position - transform.position;
// Move the plants in the same direction
transform.position = Vector2.Lerp(transform.position, transform.position + direction, Time.deltaTime);