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

Need Help with remote functions for my admin panel that i made from scratch (?)

Asked by 3 years ago
Edited 3 years ago

I was making a game but I came across an error when I was making a admin panel from scratch. I was stuck with this for a lot of weeks to research. If you could help it would be greatly appreciated!

local script (in TextLabel):

local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = game.ReplicatedStorage.Hi
local Amount = script.Parent.Panel.Buttons.Cash.CashAmount
local Value = script.Parent.Panel.Buttons.Cash.CashType
local buttons = script.Parent.Panel.Buttons.Cash

buttons.MouseButton1Click:Connect(function()
    createPartEvent:FireServer(Amount, Value)
end)

script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = game.ReplicatedStorage.Hi

createPartEvent.OnServerEvent:Connect(function(player, text, value)
    local Stats = player:WaitForChild("Stats")

    print("recieved")
    wait(.1)
    if text == "Cash" then
        Stats.Cash.Value = value   print("Work")

    elseif text == "Multiplier" then
        Stats.Multiplier.Value = value   print("Work")

    end

end)

(output dosent have errors)

0
What is the exact problem? I am suspecting that it's about parameter that is firing from localScript Somone_exe 224 — 3y
0
sorry for the late response! the local script fires the remote function but it wont work in the script it only prints out "recieved" RarestNameMan 7 — 3y
0
hmm I see now Somone_exe 224 — 3y
0
Check the solution that I wrote! because I figured the solution. Somone_exe 224 — 3y

2 answers

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

The interpretation of the remote function that you write is different.

The thing you are firing is (CashAmount, CashType) BUT the interpretation of onServerEvent in server script just interprets CashAmount as text instead of CashType. That's why it did print "received" but never "work". EDIT: The value sent is the instance NOT the value of the instance.

Confusing right? Here is the overall explanation which is easy to understand

createPartEvent:FireServer(Amount, Value) You fire amount as CashAmount and you fire value as CashType. The value sent is always instance and never value of the instance.

createPartEvent.OnServerEvent:Connect(function(player, text, value) -- This is server side function

player parameter is unused

the server received text as amount (cashAmount) instead of cashType which value instead receive Value (cashType). The server also get text and value as an instance

You are trying to compare CashAmount to text which supposed to check CashType, that's why the check is failed. You can even put else and use print("Not Work!") and it will output Not Work! EDIT: Ignore the italic text, You are trying to compare the value sent (Instance) to a number which never works because the value is different when gotten from the client.

== First Solution for your code (Server Side) ==

-- SERVER SIDE SOLUTION NEVER WORKS AFTER MORE INFORMATION --

-- THE SERVER-SIDE SOLUTION BELOW IS ARCHIVED --

-- USE CLIENT-SIDE SOLUTION INSTEAD OF SERVER-SIDE IF YOU HAVE USED SERVER-SIDE SOLUTION THEN YOU HAVE TO REVERT THE CHANGE--

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = game.ReplicatedStorage.Hi

createPartEvent.OnServerEvent:Connect(function(player, value, text) -- Switching the parameter
    local Stats = player:WaitForChild("Stats")

    print("recieved")
    wait(.1)
    if text == "Cash" then
        Stats.Cash.Value = value   print("Work")

    elseif text == "Multiplier" then
        Stats.Multiplier.Value = value   print("Work")

    end

end)

== Second Solution (Client Side) ==

-- THE SOLUTION HAVE BEEN UPDATED IN 15TH APRIL 2021 (EUROPEAN TIME) --

local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = game.ReplicatedStorage.Hi
local Amount = script.Parent.Panel.Buttons.Cash.CashAmount
local Value = script.Parent.Panel.Buttons.Cash.CashType
local buttons = script.Parent.Panel.Buttons.Cash

buttons.MouseButton1Click:Connect(function()
    createPartEvent:FireServer(Value.Value, Amount.Value) -- Added value
end)

NOTE: You can only choose the client-side solution.

In the future, you probably want to check the parameter that client/server fire or received and make sure that server/client interpret the fired message correctly.

EDIT: Also check if you're trying to fire the value of the instance instead of the instance itself in the future too! you can check the value by using the print() function such as print(Value). This is really useful in helping debugging bugs.

Happy Scripting!

0
If you found this solution work! then you can accept this question and get points for both of us! this solution can be seen by other user in the future too! Somone_exe 224 — 3y
0
sorry but i tried i even added "else print("not work") it says not work and i only chose one solution from your answer RarestNameMan 7 — 3y
0
so i found out an error but it dosent show the error from the client side here: "local Amount = script.Parent.Panel.Buttons.Cash.CashAmount local Value = script.Parent.Panel.Buttons.Cash.CashType" I said this was an error because i forgot to put ".Text", ".Value". I did that but it still says "not work" RarestNameMan 7 — 3y
0
Sorry for late response, It reached night time yesterday and I have to sleep BUT I will rewrite the answer if there's more info Somone_exe 224 — 3y
View all comments (3 more)
0
i have school too RarestNameMan 7 — 3y
0
ok so, i did everything correct i copied your script and i tried to print the value and the amount. it is still wrong but it prints the value and amount correctly RarestNameMan 7 — 3y
0
Nevermind it worked thanks alot! you deserve reputation RarestNameMan 7 — 3y
Ad
Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago

I think I see a problem here. You see, in the local script, you didn't reference what the "text" parameter is so the serverscript thinks that text is just nil.

Answer this question