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

Can someone help me with Onserverinvoke rebirth code?

Asked by 5 years ago
Edited 5 years ago

here is the code on the local script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local starterRebirthAmount = 5000

local player = game.Players.LocalPlayer
local mainFrame = script.Parent:WaitForChild("MainFrame")
local rebirthMenu = mainFrame:WaitForChild("RebirthMenu")
local mainButton = script.Parent:WaitForChild("MainButton")
local rebirthButton = rebirthMenu:WaitForChild("RebirthButton")
local strengthToRebirth = rebirthMenu:WaitForChild("StrengthToRebirth")
local rebirths = player:WaitForChild("leaderstats").Rebirths


strengthToRebirth.Text = "You need at least "..math.floor((starterRebirthAmount + (rebirths.Value) * math.sqrt(50000000))).."strength to rebirth"

mainButton.MouseButton1Click:Connect(function()
    mainFrame.Visible = not mainFrame.Visible
end)


rebirthButton.MouseButton1Click:Connect(function()
    local result = replicatedStorage.Remotes.Rebirth:FireServer()

    if result == true then
        rebirthButton.Text = "Nice Job 8D"
        wait(5)
        rebirthButton.Text = "CLICK HERE TO REBIRTH"
    elseif result == "NotEnoughStrength" then
        rebirthButton.Text = "Sorry :'("
        wait(1)
        rebirthButton.Text = "CLICK HERE TO REBIRTH"

    end
end)

rebirths:GetPropertyChangedSignal("Value"):Connect(function()
    strengthToRebirth.Text = "You need at least "..math.floor((starterRebirthAmount + (rebirths.Value) * math.sqrt(50000000))).."strength to rebirth"
end)

and here is the normal script

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local starterRebirthAmount = 5000
local rebirth = game:GetService("ReplicatedStorage").Remotes.Rebirth
local cooldown = 0.1

replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)

    if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

    local debounce = remoteData:WaitForChild(player.Name).Debounce

    if debounce.Value == false then

        debounce.Value = true

        player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1 * (player.leaderstats.Rebirths.Value + 1)

        wait(cooldown)

        debounce.Value = false

    end
end)

function rebirth.OnServerInvoke:Connect(player)
        if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

        local rebirths = player.leaderstats.Rebirths

        if player.leaderstats.Strength.Value >= (math.floor((starterRebirthAmount + (rebirths.Value) * math.sqrt(50000000)))) then

            rebirths.Value = rebirths.Value + 1

            player.leaderstats.Strength.Value = 0

            player:LoadCharacter()
            return true
    else return "NotEnoughStrength"
        end
end

and the output:

  21:25:56.263 - OnServerInvoke is not a valid member of RemoteEvent
21:25:56.269 - Stack Begin
21:25:56.273 - Script 'ServerScriptService.Remotes', Line 26
21:25:56.275 - Stack End

more details will be shown, I think there was an update that messed this up... or I'm just dumb

0
No problem! Glad I could help. User#26971 0 — 5y
0
there's another thing wrong with my script though. It's in the recent scipts. i forgot to put the output gueli844 -1 — 5y
0
Post another question, like I said. User#26971 0 — 5y
0
Oh, you did. Looking at it now. User#26971 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Your code has two primary problems causing the remote function to fail:

A.

You've got to use a RemoteFunction, not a RemoteEvent. Make sure you're using the correct type of object. All you have to do to fix this is to go into the Remotes folder (I'm assuming it's a folder) in ReplicatedStorage and change the Rebirth object from a RemoteEvent to a RemoteFunction.

B.

Your second problem is that OnServerInvoke isn't like an event listener. You cant do the standard :Connect(function() that you're used to.

Binding a function to OnServerInvoke is done with the assignment operator =, and not with an event. That is because OnServerInvoke is a callback and expects a function to be assigned to it. When the RemoteFunction is invoked, it will execute the function that was assigned to the onInvoke function.

So, on line 26, it should be

rebirth.OnServerInvoke = function(player)
    -- code
end

neither

function rebirth.OnServerInvoke:Connect(player)
    -- code
end

nor

rebirth.OnServerInvoke:Connect(function(player)
    -- code
end)

will work. I hope this helps! Have a great day scripting.

If this fixes your problem, please accept this answer. If you have a different problem that occurs once you fix this one, then accept this answer and post a different question.

0
thanks!! :) gueli844 -1 — 5y
0
please look up, im to lazy to copy it XD gueli844 -1 — 5y
0
it worked, but put it in the answer section to get rep gueli844 -1 — 5y
Ad

Answer this question