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

Attempt to concatenate instance with string?

Asked by 3 years ago
Edited 3 years ago

Stack Begin  -  Studio Script 'ServerScriptService.Script', Line 50  -  Studio  -  Script:50 Stack End  -  Studio

Script:

local name = "Player"

local serverScriptService = game:GetService("ServerScriptService")
local chatServiceModule = require(serverScriptService:WaitForChild("ChatServiceRunner").ChatService)
local nameColors = {
    Color3.fromRGB(253, 41, 67), -- BrickColor.new("Bright red").Color,
    Color3.fromRGB(1, 162, 255), -- BrickColor.new("Bright blue").Color,
    Color3.fromRGB(2, 184, 87), -- BrickColor.new("Earth green").Color,
    BrickColor.new("Bright violet").Color,
    BrickColor.new("Bright orange").Color,
    BrickColor.new("Bright yellow").Color,
    BrickColor.new("Light reddish violet").Color,
    BrickColor.new("Brick yellow").Color,
}

local function getNameValue(name)
    local value = 0
    for index = 1, #name do
        local cValue = name:sub(index, index):byte()
        local reverseIndex = #name - index + 1
        if #name % 2 == 1 then
            reverseIndex = reverseIndex - 1
        end
        if reverseIndex % 4 >= 2 then
            cValue = -cValue
        end
        value = value + cValue
    end

    return value
end

local speaker = chatServiceModule:GetSpeaker(name)
if not speaker then
    speaker = chatServiceModule:AddSpeaker(name)
    speaker:SetExtraData("NameColor", nameColors[getNameValue(name) % #nameColors + 1])
    speaker:JoinChannel("All")
end
game.ReplicatedStorage.FireChat.OnServerEvent:Connect(function(player, hour, min)
local Country = game:GetService("LocalizationService"):GetCountryRegionForPlayerAsync(player)
wait(2)
speaker:SayMessage("I know where you live", "All")
wait(3)
speaker:SayMessage("I am coming to your house", "All")
wait(3)
speaker:SayMessage("I know you live in ", Country.. "All")
wait(3)
speaker:SayMessage("I know your IP is: ", math.random(1,200).."."..math.random(1,200)..".".. ".1.1.".. "All")
wait(3)
speaker:SayMessage("I know your local time is ", hour.. ":".. min.. "All")
end)

LocalScript:

local player = game.Players.LocalPlayer
local playertime = os.date("*t", os.time())
local hour, min = playertime.hour, playertime.min
game.ReplicatedStorage.FireChat:FireServer(player, hour, min)

1 answer

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

the onserverevent already receives the player variable by default

local player = game.Players.LocalPlayer
local playertime = os.date("*t", os.time())
local hour, min = playertime.hour, playertime.min
game.ReplicatedStorage.FireChat:FireServer(hour, min)

so in your case it was

OnServerEvent:Connect(function(player, player, hour, min)

and thus you concat an instance with a string

this is what your code should be

local player = game.Players.LocalPlayer
local playertime = os.date("*t", os.time())
local hour, min = playertime.hour, playertime.min
game.ReplicatedStorage.FireChat:FireServer(hour, min)
local name = "Player"

local serverScriptService = game:GetService("ServerScriptService")
local chatServiceModule = require(serverScriptService:WaitForChild("ChatServiceRunner").ChatService)
local nameColors = {
    Color3.fromRGB(253, 41, 67), -- BrickColor.new("Bright red").Color,
    Color3.fromRGB(1, 162, 255), -- BrickColor.new("Bright blue").Color,
    Color3.fromRGB(2, 184, 87), -- BrickColor.new("Earth green").Color,
    BrickColor.new("Bright violet").Color,
    BrickColor.new("Bright orange").Color,
    BrickColor.new("Bright yellow").Color,
    BrickColor.new("Light reddish violet").Color,
    BrickColor.new("Brick yellow").Color,
}

local function getNameValue(name)
    local value = 0
    for index = 1, #name do
        local cValue = name:sub(index, index):byte()
        local reverseIndex = #name - index + 1
        if #name % 2 == 1 then
            reverseIndex = reverseIndex - 1
        end
        if reverseIndex % 4 >= 2 then
            cValue = -cValue
        end
        value = value + cValue
    end

    return value
end

local speaker = chatServiceModule:GetSpeaker(name)
if not speaker then
    speaker = chatServiceModule:AddSpeaker(name)
    speaker:SetExtraData("NameColor", nameColors[getNameValue(name) % #nameColors + 1])
    speaker:JoinChannel("All")
end
game.ReplicatedStorage.FireChat.OnServerEvent:Connect(function(player, hour, min)
local Country = game:GetService("LocalizationService"):GetCountryRegionForPlayerAsync(player)
wait(2)
speaker:SayMessage("I know where you live", "All")
wait(3)
speaker:SayMessage("I am coming to your house", "All")
wait(3)
speaker:SayMessage("I know you live in " ..Country, "All")
wait(3)
speaker:SayMessage("I know your IP is: ".. math.random(1,200).."."..math.random(1,200)..".".. ".1.1.", "All")
wait(3)
speaker:SayMessage("I know your local time is ".. hour.. ":".. min, "All")
end)

i removed the other errors in your code

0
Hello, tranks for your help but it didn't work. SimulationStHolder 2 — 3y
0
Now no error appears but it only works up to this line speaker: SayMessage ("I am coming to your house", "All") SimulationStHolder 2 — 3y
0
Doritos... Am like doritos malachiRashee 24 — 3y
0
i removed other mistakes in your code VerdommeMan 1479 — 3y
0
thank you very much! SimulationStHolder 2 — 3y
Ad

Answer this question