Remote Function Help?

Hello, I am a pretty new user to Roblox Scripting, I’ve only scripted for half a year. Consequently, being new to Roblox scripting, I run into many problems that I just can figure out.

Heres my problem:
I have just learned how to use remote events on Roblox, I know how to fire them and use them in scripts. But, my problem is that the remote event fired from a local script lasts too long. Is there anyone who can help me?
Here are pictures and videos on my problem:
Script(Collection)


Local Script(Keybind)

Video1 e pressed after hover


Video2 e pressed before hover

if you know how to fix this please tell me, I’ve been thinking for two days, and I still can’t find a reason.

1 Like

RemoteEvents and RemoteFunctions generally take a small amount of time to communicate between server and client. This is unavoidable, but you can create clever tricks to make it seem faster.

Try doing the mouse check through the client as well. You can get the mouse from the player using Player:GetMouse() This will allow you to detect where the mouse is currently pointing in the 3D space and you can pick up whether it is hovering over a specific object. By doing the mouse hover check on the client, you can check whether both parameters are met and delete the part only on the client. Then you can send the info to the server and let the server do it’s own check to avoid hacking. To the player the part was deleted instantly, but to the server and other players it was deleted within a short time frame.

By doing this method, make sure the server only accepts the first request, that way multiple players can’t click the same object.

Sorry about the misconception, as I said, I’m pretty new to Roblox Studio, so I might be wrong sometimes. What I was trying to say was that the fired event is taking too long to stop firing, sorry, I am not so good at explaining things.

I don’t get it, how do you detect the mouse hovering over an object? Can you give me an example? Like, how do you do it with a script?

This wiki page provides an example on how to obtain the mouse object from the player, as well as using it’s properties to find a 3D space in the world from it’s position. The property Target will provide you with what you need.

1 Like

so do I put this in the script?:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Collect = ReplicatedStorage:WaitForChild("Collect")

script.Parent.ClickDetector.MouseHoverEnter:Connect(function(player)
        local Mouse = player:GetMouse
	Collect.OnServerEvent:Connect(function()
        if Mouse.Target = script.Parent then
		if script.Parent.ClickDetector.MouseHoverEnter then
			local Stats = player:FindFirstChild("Stats")
			if Stats ~= nil then
				local Log = Stats:WaitForChild("Log")
				if Log ~= nil then
					Log.Value = Log.Value + 1
					script.Parent.Parent:Destroy()
				end
			end
		end
        end
	end)
end)

off topic question:
how do you paste scripts

No, the Mouse object should only be obtained from a local script. The whole point of using it is to try and avoid the delay between client and server communication. Use the mouse object to detect it’s target from the local script and have the part be deleted instantly from the client, and then send the information over to the server through the RemoteEvent for the part to be removed from the server as well.

You can copy program by highlighting the code and pressing ctrl+c on windows
You can paste program by pressing ctrl+v on windows

local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Collect = ReplicatedStorage:WaitForChild("Collect")
local Mouse = game.Players.LocalPlayer:GetMouse()

UIS.InputBegan:Connect(function(input, processed)
	if input.UserInputType.Name == "Keyboard" and processed == false then
local part = Mouse.Target
		if input.KeyCode.Name == "C" then
part:Destroy()
			Collect:FireServer()
			print("pressed e")
		end
	end
end)

like this?

By the way, the copy and pasting didn’t work, yes, I’m on windows.

Sorry if I’m being a bit annoying, I’m a bit stressed out.

Yes, but you should add a check within the local script to make sure you’re deleting the item you want deleted, not just deleting some random item. In theory this should remove the item immediately from the client while the server can catch up.

If control+c and control+v isn’t working then I have no idea what to tell you. Use right click on highlighted code and click copy, then right click at where you want to paste and click paste.

Thank you, i added:
if part.Parent:FindFirstChild(“HitBox”) then

1 Like