How would I go about making Interactive plants/grass

Oh, my bad. Never played The Wild West,

I believe you can move the plant model to a desired position when either a player’s distance from it is really close[meaning he’s walking into it], and if he actually reached distance 0, you could make the plant move aside or something.

A few articals on moving models:

1 Like

thanks, I will give that a try, only one thing I want to make it so that the plant moves in the direction the player is moving

here is an example, the plant tweens in the direction the player is walking
image
image

I think you can use CFrame.lookAt and look at the character’s torso.

1 Like

thanks! that’s a good idea, can you show me a code for that because I have tried that but I don’t think I did the code right. I tried basing it off this other persons topic but i could not get it to work

1 Like

here is Tyridge77’s post about it so you can get a better understanding

1 Like

CFrame.lookAt(plant.Position, torso.Position)

1 Like

thanks! i think this will work

Take a look onto CFrame and lookAt, they can help you alot :

https://developer.roblox.com/en-us/api-reference/datatype/CFrame

1 Like

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

this is the grass model

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
2 Likes