-
What do you want to achieve? Keep it simple and clear!
I’m making a farming game and im trying to get the plot selection script to not interfere with
the highlighter script. -
What is the issue? Include screenshots / videos if possible!
The issue is when after unequipping the seeds, when you equip the shovel
the plot selection script is still active and executes with the shovel script at the same time.
Here’s a video to gain a better understanding:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to make sure the mouse.targetfilter would be applied to the plots only when the shovel is equipped but that only made the shovel’s script break upon testing.
This particular issue is kind of too exclusive as I can’t find other posts of people having the same issue as I am.
Here’s the code for both scripts:
--- Plot Highlighter Script
local shovel = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlacePlot = ReplicatedStorage.PlacePlot
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
shovel.Equipped:Connect(function()
local plot = ReplicatedStorage.Plot_placeholder:Clone()
plot.Parent = workspace
local posLimit = math.clamp(-5,-4,-3.5)
plot.Position = Vector3.new(mouse.Hit.X, posLimit, mouse.Hit.Z)
mouse.TargetFilter = plot
plot.Material = Enum.Material.Mud
plot.BrickColor = BrickColor.new("Lime green")
plot.Transparency = 0.5
plot.CanCollide = false
if player:DistanceFromCharacter(mouse.Hit.Position) > 40 then
plot.BrickColor = BrickColor.new("Really red")
elseif player:DistanceFromCharacter(mouse.Hit.Position) <= 40 then
plot.BrickColor = BrickColor.new("Lime green")
end
if mouse.Target == workspace.Map_1.Base then
plot.BrickColor = BrickColor.new('Lime green')
else
plot.BrickColor = BrickColor.new('Really red')
end
mouse.Move:Connect(function()
plot.Position = Vector3.new(mouse.Hit.X, posLimit, mouse.Hit.Z )
if player:DistanceFromCharacter(mouse.Hit.Position) > 20 then
plot.BrickColor = BrickColor.new('Really red')
elseif player:DistanceFromCharacter(mouse.Hit.Position) <= 20 then
plot.BrickColor = BrickColor.new("Lime green")
end
if mouse.Target == workspace.Map_1.Base then
plot.BrickColor = BrickColor.new('Lime green')
else
plot.BrickColor = BrickColor.new('Really red')
end
end)
end)
shovel.Unequipped:Connect(function()
local plot = ReplicatedStorage.Plot_placeholder:Clone()
if game.Workspace:FindFirstChild("Plot_placeholder") then
game.Workspace:FindFirstChild("Plot_placeholder"):Destroy()
end
end)
shovel.Activated:Connect(function()
if game.Workspace:FindFirstChild("Plot_placeholder") then
local placeholder = game.Workspace:FindFirstChild("Plot_placeholder")
if placeholder then
if placeholder.BrickColor == BrickColor.new('Lime green') then
PlacePlot:FireServer(placeholder.Position)
else
return
end
end
end
end)
--- Plot Selection Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local carrotseeds = script.Parent
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
carrotseeds.Equipped:Connect(function()
if mouse.TargetFilter ~= nil then
mouse.TargetFilter = nil
end
mouse.Move:Connect(function()
local target = mouse.Target
if target and target.Name == "Plot" then
target.BrickColor = BrickColor.new("Lime green")
elseif target and target.Name ~= "Plot" then
for i, v in pairs(workspace.Plots:GetChildren())do
v.BrickColor = BrickColor.new("Reddish brown")
end
end
end)
mouse.Idle:Connect(function()
local target = mouse.Target
if target and target.Name == "Plot" then
target.BrickColor = BrickColor.new("Lime green")
elseif target and target.Name ~= "Plot" then
for i, v in pairs(workspace.Plots:GetChildren())do
v.BrickColor = BrickColor.new("Reddish brown")
end
end
end)
end)
carrotseeds.Unequipped:Connect(function()
if mouse.TargetFilter == nil then
mouse.TargetFilter = workspace.Plots
else
mouse.TargetFilter = nil
end
end)
Hope these references are enough for anyone to come up with a conclusive answer to this problem.
I’m not the best programmer so I am still learning the quirks and kinks as we speak.
Thanks!