Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years 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

01local player = game.Players.LocalPlayer
02local tool = script.Parent
03local handle = tool:WaitForChild("Handle")
04local mouse = player:GetMouse()
05 
06local PlaceBlock = Instance.new("Part")
07PlaceBlock.Size = Vector3.new(3,3,3)
08PlaceBlock.Anchored = true
09PlaceBlock.CanCollide = false
10PlaceBlock.Transparency = 0.5
11 
12local placing = false
13 
14handle.MouseEnter:Connect(function()
15    if tool.Parent == player.Character and placing == false then
View all 67 lines...
0
WHAT IS THIS SPAGHETTI CODE ABDJackioZoAlt1 37 — 2y
0
ascii art on coding wtf Xapelize 2658 — 2y
0
is the "placing" variable ever set to true? the8bitdude11 358 — 2y
0
i recommend using elseif so it looks a bit neater lol JmoneyPlayzOfficial 49 — 2y
View all comments (2 more)
0
I edited the script but it gives me an error that says: MariamOMG090 9 — 2y
0
MouseEnter is not a valid member of Part "Players.PreviousSchmuck.Backpack.PlaceBlock.Handle" - Client - LocalScript:14 MariamOMG090 9 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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:

01handle.ClickDetector.MouseHoverEnter:Connect(function()
02    if tool.Parent == player.Character and placing == false then
03        placing = true
04        PlaceBlock.Parent = workspace
05    end
06end)
07 
08handle.ClickDetector.MouseHoverLeave:Connect(function()
09    if placing == true then
10        placing = false
11        PlaceBlock:Destroy()
12    end
13end)

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:

1local Player = game.Players.LocalPlayer
2local Mouse = Player:GetMouse()
3 
4Mouse.Move:Connect(function()
5    local Target = Mouse.Target
6    if Target ~= nil then -- If the target is pointed to things such as the sky, it will be nil
7        -- Code for what to do with the target here.
8    end
9end)

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 — 2y
1
Nvm i fixed it myself MariamOMG090 9 — 2y
Ad

Answer this question