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

I am having issues with Remote Events?

Asked by 4 years ago

So i want a cube of light to be placed wherever the player has his/her mouse when they press R. I'm not sure what the issue is with the code I made.

Local Script:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local RepStorage = game:GetService("ReplicatedStorage")
local DeletePart = RepStorage.DeletePart
local UIS = game:GetService("UserInputService")
local part = game.Workspace.deletepart

UIS.InputBegan:Connect(function(input)
    local Hitposition = Mouse.Hit
    if input.KeyCode == Enum.KeyCode.R then
        print("R Pressed")
        if Hitposition == nil then
            DeletePart:FireServer(Hitposition)
        end
    end
end)

Server Script:

local RepStorage = game:GetService("ReplicatedStorage")
local DeletePart = RepStorage.DeletePart
local Cube = game.ServerStorage.LightCube:Clone()
local Cooldown = {}

DeletePart.OnServerEvent:Connect(function(Player, Position)
    if Cooldown[Player.name] then return warn(Player.Name.." is on cooldown")end
    Cooldown[Player.Name] = os.time
    Cube.Name = string.format("%s part", tostring (Player.name))
    Cube.Parent = game.Workspace
    Cube.CFrame = Position

    delay(2,function() -- 2 = cooldown time
        Cooldown[Player.Name] = nil
    end)
end)
0
Thanks guys for all the help! Kittymuffin323 -10 — 4y
0
How do you know there even is an issue if you don't know what the issue is? SteamG00B 1633 — 4y
0
We can't help you if you don't give us more than "issue" SteamG00B 1633 — 4y
0
Could you be a bit more descriptive? What is not happening the way you want it to? appxritixn 2235 — 4y
0
What exactly is the problem? Is the cube not appearing? If so, I think I know the problem; and that is because you used mouse.Hit and not mouse.Hit.Position. xxIamInevitable 2 — 4y

Answer this question