thanks! I will do that right now
this is what I scripted but it does not work, Do you know why?
local grass = script.Parent.Parent.Grass
local ts = game:GetService(“TweenService”)
grass.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local hum = hit.Parent:FindFirstChild("Humanoid")
local movedir = hum.MoveDirection.Unit
print(movedir.X, movedir.Z)
local facevector = grass.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Z))
local tween = ts:Create(grass, TweenInfo(.5), {CFrame = grass.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Y))})
tween:Play()
end
end)
it says I ERROR: attempted to call a table value
What line of the script? You need to give all the info about the error possible.
ooh sorry ya line it is 15 i cant figure out why
so I was thinking and I decided to put all the plants in a folder, so I rewrote the script to make it work for all plants. The issue is that that doesn’t even work I set it to move the primary part but it won’t work. Btw I fixed the line 15 issue I had to put 0.5 in the TweenInfo spot
here is the new script
local grassfolder = workspace.Grass
local ts = game:GetService(“TweenService”)
while wait(.1) do
for i, grass in pairs(grassfolder:GetChildren()) do
grass.HitBox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local hum = hit.Parent:FindFirstChild("Humanoid")
local movedir = hum.MoveDirection.Unit
print(movedir.X, movedir.Z)
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
end
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);