Wins system script not working!

Hello!

I am currently trying to make a win system! When a part is touched it will change a text label to “Wins: 1” and every time you touch the part it will add one win. I probobally made a stupid mistakes on this script but I am trying to use a remote event in this Process. (Please try to include one because I am trying to learn about them.)

Edit:
(I am also trying to make the wins for the local player only and create a leader stat for that!(Thanks for the suggestion @IceStorm775 ))

Script (Inside of part):

local RS = game:GetService("ReplicatedStorage")
local label = game.StarterGui.ScreenGui.Wins.Text
local FireReplicated = true
part.Touched:Connect(function()
	RS.GiveWins:FireClient()
	print("serverFired")
end)

LocalScript (Inside of text label)

local RS = game:GetService("ReplicatedStorage")
local label = game.StarterGui.ScreenGui.Wins.Text
RS.GiveWins.OnClientEvent:Connect(function()
	if RS.GiveWins == true then
		label = "Wins: "..math.random(1)
	else
		error("Wins Not given.")
	end
end)

It ends up giving me the

 Unable to cast value to Object

error I know that there is a FireClient() In the script but I don’t know what to put in it…

Thanks for the help,

BasicButterBoy

PS,

I want to say that I am learning how to script so could you explain the script when it is finished. (Like with those like dash things (eg - - this does this!))

9 Likes

In what line of the script is the error? also why are you using math.random(1)?

1 Like

Dont mide that… I just cant seem to find a way to count up the wins… I am currently making a 1+ jump per second obby thing :skull:

EDIT:

FireClient() is where the error is happening

1 Like

Is the wins specific to the player or the server, because if its specific to the player you may want to add it to a leaderstat instead

Ok i probobally need to add that into the topic post.

‘GiveWins’ which is the RemoteEvent is an instance which you cannot check (cast) with a value (true which is a boolean).

If the OnServerEvent fires without an error, that probably means that the RemoteEvent exists.

this is basically what it’s saying:

Unable to check if GiveWins is true
(because GiveWins is an object and you can’t cross check it with values like booleans or integers).

1 Like

Yes I do recognise that I am just at the point where I need to almost redo all the scripts…

1 Like

Should I change it to this… It most likely wont do anything…

local RS = game:GetService("ReplicatedStorage")
local label = game.StarterGui.ScreenGui.Wins.Text
RS.GiveWins.OnClientEvent:Connect(function()
	if RS.GiveWins.OnClientEvent == true then
		label = "Wins: "..math.random(1)
	else
		error("Wins Not given.")
	end
end)

Ill just do a few scripts alr

In a script in ServerScriptService put

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Jump = Instance.new("NumberValue")
	Jump.Name = "JumpPower"
	Jump.Parent = leaderstats
	
local Wins = Instance.new("NumberValue")
Wins.Name = "Wins"
Wins.Parent = leaderstats

	while wait(1) do
		Jump.Value += 1
		plr.Character.Humanoid.JumpPower = Jump.Value
	end
end)

In the script inside the part do

local part = script.Parent
local RS = game:GetService("ReplicatedStorage")
local label = game.StarterGui.ScreenGui.Wins.Text
local FireReplicated = true
part.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:FindFirstChild(part.Parent.Name)
		plr.leaderstats.Wins.Value += 1
		RS.GiveWins:FireClient(plr)
	end
end)

In a local script inside the text label put

local RS = game:GetService("ReplicatedStorage")
local label = game.Players.LocalPlayer.PlayerGui.ScreenGui.Wins
RS.GiveWins.OnClientEvent:Connect(function()
	label.Text = "Wins: "..game.Players.LocalPlayer.leaderstats.Wins.Value
end)

If something gives you an error please tell me I kind of rushed this

2 Likes

I already have a jump script set up…

you said u needed to redo all the scripts so i did

1 Like

Sorry about the last post i am a bit careless and tried… (didnt read thru the other post correctly)

I am getting a error and could you explain the script a little bit…
image

That error indicates that you did not set up the leaderstats properly. Can you send the script where you set up the leaderstats?

The script is here:

local part = script.Parent
local RS = game:GetService("ReplicatedStorage")
local label = game.StarterGui.ScreenGui.Wins.Text
local FireReplicated = true
part.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:FindFirstChild(part.Parent.Name)
		plr.leaderstats.Wins.Value += 1
		RS.GiveWins:FireClient(plr)
	end
end)

no thats not what i meant for the leaderstats, put the first code i sent in a script in ServerScriptService

i think he did and its giving him the error

nah i tested my script and it worked

I did that but in the +1 jump script Hold on a second let me move it

This is not the right script, I think you have a script somewhere that makes the leaderstats for the player. You need to send me that one