Hello! I made a simple script where you can plant a seed in the ground using the mouse.
When the player tries to plant the seed, the seed just goes towards the player’s camera.
I assumed that’s because I needed to add the seed to the mouse targetfilter, which I did, but nothing changed.
Here’s a video so you can understand better of what’s happening:
https://gyazo.com/f180ebd3170f98aafc3067fb4d1f955e
This is the localscript (it’s inside the seed tool):
local uis = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local isplacing = false
local canspawn = false
local itemplace
uis.InputBegan:Connect(function(input,typing)
if typing then return end
script.Parent.keyfire:FireServer(input.KeyCode)
end)
mouse.Move:Connect(function()
if isplacing == false then return end
itemplace:MoveTo(mouse.Hit.Position)
local rayorigin = itemplace.Handle.Position
local rayDirection = Vector3.new(0,-1,0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {itemplace,game.Players.LocalPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayorigin, rayDirection, raycastParams)
if raycastResult then
if raycastResult.Material == Enum.Material.Grass or raycastResult.Material == Enum.Material.LeafyGrass then
itemplace.Highlight.FillColor = Color3.fromRGB(13, 255, 0)
canspawn = true
else
itemplace.Highlight.FillColor = Color3.fromRGB(255,0,0)
canspawn = false
end
else
itemplace.Highlight.FillColor = Color3.fromRGB(255,0,0)
canspawn = false
end
end)
script.Parent.Equipped:Connect(function()
itemplace = game.ReplicatedStorage.placeableitems.palmtreeseed:Clone()
itemplace.Parent = workspace
mouse.TargetFilter = itemplace
isplacing = true
end)
script.Parent.Unequipped:Connect(function()
itemplace:Destroy()
isplacing = false
end)
script.Parent.Activated:Connect(function()
if isplacing == false or itemplace == nil or canspawn == false then return end
itemplace:Destroy()
game.ReplicatedStorage.placeitem:FireServer(script.Parent.Name,itemplace,mouse.Hit.Position)
end)