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!))
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)
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
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)