0

# [SOLVED] when block hovered over it shows a 0.5 transparent block. why is it not working?

Edited 1 month ago

when you hover over a block its supposed to show a 0.5 transparent block. The block has to be named "Cannotdelete" so you can hover over it. But the script is not working. Please somebody tell me why. Gives me an error that says: MouseEnter is not a valid member of Part "Players.PreviousSchmuck.Backpack.PlaceBlock.Handle" - Client - LocalScript:14

local player = game.Players.LocalPlayer
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local mouse = player:GetMouse()

local PlaceBlock = Instance.new("Part")
PlaceBlock.Size = Vector3.new(3,3,3)
PlaceBlock.Anchored = true
PlaceBlock.CanCollide = false
PlaceBlock.Transparency = 0.5

local placing = false

handle.MouseEnter:Connect(function()
if tool.Parent == player.Character and placing == false then
placing = true
PlaceBlock.Parent = workspace
end
end)

handle.MouseLeave:Connect(function()
if placing == true then
placing = false
PlaceBlock:Destroy()
end
end)

local function placeBlock(target, surface)
if surface.Name == "Top" then
PlaceBlock.CFrame = CFrame.new(target.Position + Vector3.new(0,1.5,0))
elseif surface.Name == "Bottom" then
PlaceBlock.CFrame = CFrame.new(target.Position + Vector3.new(0,-1.5,0))
elseif surface.Name == "Right" then
PlaceBlock.CFrame = CFrame.new(target.Position + Vector3.new(1.5,0,0))
elseif surface.Name == "Left" then
PlaceBlock.CFrame = CFrame.new(target.Position + Vector3.new(-1.5,0,0))
elseif surface.Name == "Back" then
PlaceBlock.CFrame = CFrame.new(target.Position + Vector3.new(0,0,1.5))
elseif surface.Name == "Front" then
PlaceBlock.CFrame = CFrame.new(target.Position + Vector3.new(0,0,-1.5))
end
end

mouse.Move:Connect(function()
if placing == true then
local target, surface = mouse.Target, mouse.TargetSurface
if target and (target.Name == "Cannotdelete" or target.Name == "Block") then
placeBlock(target, surface)
else
PlaceBlock:Destroy()
end
end
end)

tool.Equipped:Connect(function()
placing = false
if PlaceBlock.Parent == workspace then
PlaceBlock:Destroy()
end
end)

tool.Unequipped:Connect(function()
placing = false
if PlaceBlock.Parent == workspace then
PlaceBlock:Destroy()
end
end)


0
WHAT IS THIS SPAGHETTI CODE ABDJackioZoAlt1 37 — 1mo
0
ascii art on coding wtf Xapelize 2658 — 1mo
0
is the "placing" variable ever set to true? the8bitdude11 358 — 1mo
0
i recommend using elseif so it looks a bit neater lol JmoneyPlayzOfficial 49 — 1mo
0
I edited the script but it gives me an error that says: MariamOMG090 9 — 1mo
0
MouseEnter is not a valid member of Part "Players.PreviousSchmuck.Backpack.PlaceBlock.Handle" - Client - LocalScript:14 MariamOMG090 9 — 1mo

0

I don't believe mouse enter is a real event for parts.

The simple way to fix this can be to use a Click detector

However now the problem is, it shows the part as if you can click on it. To fix that, simply set the property CursorIcon to rbxassetid://0 This prevents the click detector from changing the icon.

Now we need to script it, the script would be:

handle.ClickDetector.MouseHoverEnter:Connect(function()
if tool.Parent == player.Character and placing == false then
placing = true
PlaceBlock.Parent = workspace
end
end)

handle.ClickDetector.MouseHoverLeave:Connect(function()
if placing == true then
placing = false
PlaceBlock:Destroy()
end
end)



This script simply puts the block in workspace when the click detector is hovered over and deletes it when it is not.

If you are wanting this script to go in any part with the correct name, you can add the click detectors into that part before this script runs.

However, if you still do not want it to happen with click detectors and it runs on the client, you can choose a different option. You can get the players mouse by doing local Mouse = game.Players.LocalPlayer:GetMouse().

You can then watch the mouse to see whenever it hits something. To do this you will be using Mouse.Move and Mouse.Target The code for this might look something like this:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
local Target = Mouse.Target
if Target ~= nil then -- If the target is pointed to things such as the sky, it will be nil
-- Code for what to do with the target here.
end
end)


This simply watches for when the mouse is moved then checks if there is a target. It will then run what you want it to do (can be an if statement to check if it is the correct part). You can also use Mouse.TargetFilter to filter out parts you don't want the code to run on (must have the same ancestors, e.g. have them all in the same folder) and Mouse.TargetSurface to make it do things depending on what surface of the target the mouse is pointing to.

0
It does not work, it doesnt give me errors, when I hover over a part named Cannotdelete nothing happens. MariamOMG090 9 — 1mo
1
Nvm i fixed it myself MariamOMG090 9 — 1mo