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

RemoteEvent doesn't send or OnServerEvent doesn't receive? Tool Clone won't Clone Properly?

Asked by 4 years ago
Edited 4 years ago

I have a localscript which has a MouseButton1Click. Now in that Click, I want to clone an object and put it in the clicker's backpack. Realising I can only do that in a normal script, I insert a RemoteEvent inside the Replicated Storage. After that, in a script which has the "OnServerEvent" inside ServerStorage, it will not receive, or the RemoteEvent doesn't fire. I think it's the OnServerEvent won't receive, because of the explanation below.

--LocalScript
local CanBuy = true --Checking if the player can buy the item
local player = game.Players.LocalPlayer --Defining player
local GC = game.Workspace.SI.GravityCoil --Defining the place where Gravity Coil is
local E = game.ReplicatedStorage.RemoteEvent --Defining the location of RemoteEvent
local GCT = player.PlayerGui.Gui.SpecialItemsFrame.GravityCoil.GravityCoilBuy --Defining a text message
script.Parent.MouseButton1Click:Connect(function() --The Mouse Click
    if CanBuy then --If CanBuy is true, which it is from the 1st line.
        print(player.Name) --Checks who did it
        E:FireServer(GC) --Fires the server, and has GC.
        CanBuy = false --CanBuy is now false, so we wait for a bit until the person can rebuy the item.
        GCT.TextColor3 = Color3.fromRGB(255,0,0) --Changes the textcolor to red/
        for i = 10, 0, -1 do
            print(i)
            GCT.Text = i
            wait(1) -- This 'for i' is just basically a countdown until the person can rebuy it
        end
        CanBuy = true --CanBuy is set to true again, meaning that the person can get it again, the server is now fired again.
        GCT.TextColor3 = Color3.fromRGB(0, 163, 0) --Changes the color to green
        GCT.Text = "Take Here" --This was the original message.
    end
end)

Now here was my script in ServerScriptService

--Script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, Coil)
    print("Received")
    Coil:Clone().Parent = player.Backpack --Clones the Coil, and the parent is the backpack.
end)

I do not receive the print message. However, I could tell that it's just not receiving, as the localscript runs every line with no errors (meaning the countdown and all works).

I checked this with some people on discord scripting helpers, and they say the code is all right. So why won't this work?

1
Scripts that are in ServerStorage do not run. Put your script in ServerScriptService. DeceptiveCaster 3761 — 4y
0
Oh, Thanks. LennyPlayzYT 269 — 4y
0
But then it wont clone properly. LennyPlayzYT 269 — 4y
0
Now that its in SeverScriptService, both scripts run, however, the problem with tool cloning is **still** an issue. I have changed it so that the definition of the Gravity Coil is now in a server script, and it does clone, but does not act like a proper Gravity Coil. I am still having the problem. Help is appreciated. LennyPlayzYT 269 — 4y

Answer this question