Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

attempt to perform arithmetic (add) on Instance and number? (line 13)

Asked by 12 days ago
local HolderBG = script.Parent.HolderBG
local Holder = script.Parent.HolderBG.Holder
local RedeemBG = script.Parent.HolderBG.Holder.RedeemBG
local RedeemButton = script.Parent.HolderBG.Holder.RedeemBG.Redeem
local CodeBox = script.Parent.HolderBG.Holder.CodeBox
local CloseButton = script.Parent.HolderBG.Holder.Close
local EarningsButton = script.Parent.HolderBG.Holder.Earnings
local SSS = game:GetService("ServerScriptService")
local player = game.Players.LocalPlayer

RedeemButton.MouseButton1Click:Connect(function()
    local Code = CodeBox.Text
    local Redeemed = game.ReplicatedStorage.CodeGuiEvents.RedeemCode:InvokeServer(Code)

    if Redeemed == true then
        print(player.Name.." redeemed the "..CodeBox.Text.." code!")
    end
end)

game.ReplicatedStorage.CodeGuiEvents.FeedbackEvent.OnClientEvent:Connect(function(Message)
    CodeBox.Text = Message
end)

while wait() do
    if string.find(CodeBox.Text,"%s+") then
        CodeBox.TextColor3 = Color3.fromRGB(0, 0, 0)
    end
end

1 answer

Log in to vote
0
Answered by
Azarth 3114 Moderation Voter Community Moderator
12 days ago

Your error doesn't seem to pertain to this script. The fact that you tried to get ServerScriptService should have errored before line 13 anyways.

-- You can't access ServerScriptService from a LocalScript
--local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer

local HolderBG = script.Parent:WaitForChild("HolderBG")
local Holder = HolderBG.Holder
local RedeemBG = Holder.RedeemBG
local RedeemButton = RedeemBG.Redeem
local CodeBox = Holder.CodeBox
local CloseButton = Holder.Close
local EarningsButton = Holder.Earnings

RedeemButton.MouseButton1Click:Connect(function()
    local Code = CodeBox.Text
    -- Asking the server a question can cause an infinite yield/hang the server, use a remote event instead.
    ReplicatedStorage.CodeGuiEvents.FeedbackEvent:FireServer(Code)
end)

ReplicatedStorage.CodeGuiEvents.FeedbackEvent.OnClientEvent:Connect(function(Message)
    CodeBox.Text = Message
end)

--> If you can avoid using a loop, do it. 
CodeBox:GetPropertyChangedSignal("Text"):Connect(function()
    if string.find(CodeBox.Text,"%s+") then
        CodeBox.TextColor3 = Color3.new(0, 0, 0)
    else
        -- ?
    end
end)

--[[ Server RemoteEvent instead of RemoteFunction
ReplicatedStorage.CodeGuiEvents.FeedbackEvent.OnServerEvent:Connect(function(Player, Code)
    --> if not player or not code or not code is a string then assert error
    assert ( Player and Code and typeof(Code) == 'string',
        not Code and 'No code provided',
        or typeof(Code) ~= 'string' and 'Code needs to be a string'
        or 'No Player provided?!')
    if code is real and player hasn't reedeemed code then 
        ReplicatedStorage.CodeGuiEvents.FeedbackEvent:FireClient (Player, ('%s redeemed!'):format(Code) )
        -- > Do something for the code
    else
        ReplicatedStorage.CodeGuiEvents.FeedbackEvent:FireClient (Player, ('%s was not redeemed'):format(Code) )
    end
end)
--]]

Ad

Answer this question