Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

7 comments

0

btw I tried both FireClient and InvokeClient, soooo...

0

Does the function run?

0

yeah

0

the one in server, but it errors after that

0

So it doesn't send it to the client?

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)

0

it didnt work gg

1 answer

✓ Accepted answer

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)

12 comments

0

Workspace.1v1Half.home.Script:6: attempt to index local 'gui' (a nil value)

0

Damn, figured that would happen. Try it now

0

Unable to cast value to Object (Line 7, in the server script)

0

Try to print court's value: print(court.Value) to see if it is a number or object in the server script

0

I think the error is saying that the court has no Value property (unable to see value to Object)

0

it's a number

0

I have court connected a game.Players.PlayerAdded script in SSS [local court = Instance.new("IntValue", player)]

0

Change IntValue to NumberValue and see if that works.

0

Same error, I tried making both the server values numbervalues, and then we just tried making court to numbervalue, same error.

0

Changed some stuff. Tell me what it prints in the local script

2

So the court's parent is is Player or is it inside a leaderstat

1

is in player

This discussion is preserved as it was. New answers, comments, and votes are closed.