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

Connecting Scoreboard to an IntValue in Workspace? [Filtering Enabled]

Asked by 6 years ago

I want to have it so that, if the score changes, the player's scoreboard's text will change. I'm getting the error "Unable to cast value to Object". Could it be because the parameter is a player? Still a newbie on FE.

Server Script:

local RepStorage = game:GetService("ReplicatedStorage")
local ChangeScore = RepStorage:WaitForChild("ChangeScore")

local function onChange(player)
    ChangeScore:FireClient(player) --errors here
end

script.Parent.Changed:Connect(onChange) --whenever value changes, it'll connect to scoreboard's value

LocalScript:

wait(0.5)

local RepStorage = game:GetService("ReplicatedStorage")
local ChangeScore = RepStorage:WaitForChild("ChangeScore")

local player = game.Players.LocalPlayer
local pgui = player:WaitForChild("PlayerGui")
local board = pgui:WaitForChild("Scoreboard")
local court = player:FindFirstChild("Court")

local modelcourt = workspace:FindFirstChild("1v1Half") -- this is okay in a localscript right?
local home1 = modelcourt:WaitForChild("home")

local function onChange()
    if court.Value == 1 then -- i have more than one place where the scoreboard will change
        script.Parent.Text = home1.Value -- could be the error idk
    else
        board.Enabled = false
    end
end

ChangeScore.OnClientEvent:Connect(onChange)

Thanks,

LukeGabrieI

0
btw I tried both FireClient and InvokeClient, soooo... LukeGabrieI 73 — 6y
0
Does the function run? User#20388 0 — 6y
0
yeah LukeGabrieI 73 — 6y
0
the one in server, but it errors after that LukeGabrieI 73 — 6y
View all comments (3 more)
0
So it doesn't send it to the client? User#20388 0 — 6y
0
I think the problem is that you don't 'tell' what 'player' is, you can fix that by doing it like this script.Parent.Changed:Connect(function(player) end) User#20388 0 — 6y
0
it didnt work gg LukeGabrieI 73 — 6y

1 answer

Log in to vote
2
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

Local Script

wait(0.5)

local RepStorage = game:GetService("ReplicatedStorage")
local ChangeScore = RepStorage:WaitForChild("ChangeScore")

local player = game.Players.LocalPlayer
local pgui = player:WaitForChild("PlayerGui")
local board = pgui:WaitForChild("Scoreboard")
local court = player:FindFirstChild("Court")

local modelcourt = workspace:FindFirstChild("1v1Half") -- this is okay in a localscript right?
local home = modelcourt:WaitForChild("home")

court.Changed:connect(function()
    print(court.Value) -- tell me what this prints
    local courtvalue = court.Value
    if courtvalue == 1 then 
        ChangeScore:FireServer(true) -- send data to server script that is connected to the 'ChangeScore' remote
    elseif not courtvalue == 1 then 
        board.Enabled = false 
    end
end)

ChangeScore.OnClientEvent:connect(function(canchange)
    if canchange == true then 
        script.Parent.Text = home.Value
    end
end)

Server Script

local RepStorage = game:GetService("ReplicatedStorage")
local ChangeScore = RepStorage:WaitForChild("ChangeScore")

function ChangeValue(player, canchange) -- receive the data, remember the first parameter is always the player who :FireServer
    print("" .. player.Name .. " has fired ChangeScore remote!")
    if canchange then 
        ChangeScore:FireClient(true)
    end
end

ChangeScore.OnServerEvent:connect(ChangeValue)
0
Workspace.1v1Half.home.Script:6: attempt to index local 'gui' (a nil value) LukeGabrieI 73 — 6y
0
Damn, figured that would happen. Try it now hellmatic 1523 — 6y
0
Unable to cast value to Object (Line 7, in the server script) LukeGabrieI 73 — 6y
0
Try to print court's value: print(court.Value) to see if it is a number or object in the server script hellmatic 1523 — 6y
View all comments (8 more)
0
I think the error is saying that the `court` has no Value property (unable to see value to Object) hellmatic 1523 — 6y
0
it's a number LukeGabrieI 73 — 6y
0
I have court connected a game.Players.PlayerAdded script in SSS [local court = Instance.new("IntValue", player)] LukeGabrieI 73 — 6y
0
Change IntValue to NumberValue and see if that works. hellmatic 1523 — 6y
0
Same error, I tried making both the server values numbervalues, and then we just tried making court to numbervalue, same error. LukeGabrieI 73 — 6y
0
Changed some stuff. Tell me what it prints in the local script hellmatic 1523 — 6y
2
So the court's parent is is Player or is it inside a leaderstat awesomeipod 607 — 6y
1
is in player LukeGabrieI 73 — 6y
Ad

Answer this question