Re "How to Script Points/Guesses"

So earlier today I made a post asking for help with scripting guessing/points: see more information here.

And someone did point me in the right direction and was very helpful with providing information/script with the leaderstats. But something ended up happening which I’ve been trying to fix but can’t seem to figure out exactly what the problem is. Basically I guess something and instead of giving me 1 guess like it’s suppose to, it gives me 586 extra.
example2
The points work but the guesses do not.
Here is the script that was edited.

door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	local decal = script.Parent.Decal ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT)
	speaker.leaderstats.Guesses.Value = speaker.leaderstats.Guesses.Value + 1
	if (msg == string.lower(thecharacter.Value)) then 
		door.CanCollide = false  
		speaker.leaderstats.Points.Value = speaker.leaderstats.Points.Value + 2 -- Adds Points value
		door.Transparency = 0.7 
		decal.Transparency = 0.7 ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT) 
		wait(2) ----------- How long you need to wait for the door to be visible again 
		decal.Transparency = 0 ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT)
		door.CanCollide = true 
		door.Transparency = 0 
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

The part that was edited is the Guesses.Value portion and the Points.Value portion.
The script is located here:
example
It’s in the workplace in every door instance. What should I do? I’m just confused as to why the points work perfectly but the guesses are bugged.

check if the chatted event is being fired multiple times by printing something

I tried that in one of the scripts and it only printed it once. So I guess maybe it’s not that?

Well it’s because how you set it up on this line

You said that you have this same script on every door so it have this onChat event equal to number of door results in when player Chatted it will fire onChat event equal to your door number

The basic solution would be check if player is close to the door they’re guessing by doing

if (door.Position - speaker.Character.HumanoidRootPart.Position).Magnitude <= 7 then --Check if player is not far from door more than 7studs

speaker.leaderstats.Guesses.Value = speaker.leaderstats.Guesses.Value + 1
end

(Btw I typing on Phone sorry if code block messed up)

1 Like

Okay thanks! I am going to check real fast if that solves the problem!

Edit: It didn’t fix anything unfortunately. I’m still having the same problem.

Oh, I see the problem. I think for every chatted event for each script it fires because you chatted. I didn’t think of that sorry. I suggest what @RandomPlayerOne1 said by checking the door position or add a value (stage) that would work only if your on that stage.

Example:

Lets say you created a new value for your leaderstats stage

Then you did this:

door = script.Parent
function onChatted(msg, recipient, speaker) 
    local stageNumber = 1-- Change this for every stage
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	local decal = script.Parent.Decal ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT)
    if speaker.leaderstats.Stage.Value == stageNumber then
      speaker.leaderstats.Guesses.Value = speaker.leaderstats.Guesses.Value + 1
    end
	if (msg == string.lower(thecharacter.Value)) then 
		door.CanCollide = false  
        speaker.leaderstats.Stage.Value = speaker.leaderstats.Stage.Value + 1
		speaker.leaderstats.Points.Value = speaker.leaderstats.Points.Value + 2 -- Adds Points value
		door.Transparency = 0.7 
		decal.Transparency = 0.7 ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT) 
		wait(2) ----------- How long you need to wait for the door to be visible again 
		decal.Transparency = 0 ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT)
		door.CanCollide = true 
		door.Transparency = 0 
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

Though I really don’t suggest my idea since it is going to kill you since it seems like you have 586 more stages. If this is the case I also suggest using @RandomPlayerOne1 's idea but also using the tag editor with Collection Service to reduce everything to 1 script since they all essentially do the same thing. Anyways that’s all I have.

2 Likes

Your script actually gave me an idea that is working! Instead of making another leaderstats value, I made another string value and have it equal the “stage” number.

door = script.Parent
function onChatted(msg, recipient, speaker) 
	local stageNumber = 4-- Change this for every stage
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	local stage = script.Parent.Stage
	local decal = script.Parent.Decal ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT)
	if stage.Value == stageNumber then
		speaker.leaderstats.Guesses.Value = speaker.leaderstats.Guesses.Value + 1
	end
	if (msg == string.lower(thecharacter.Value)) then 
		door.CanCollide = false  
		speaker.leaderstats.Points.Value = speaker.leaderstats.Points.Value + 2 -- Adds Points value
		door.Transparency = 0.7 
		decal.Transparency = 0.7 ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT) 
		wait(2) ----------- How long you need to wait for the door to be visible again 
		decal.Transparency = 0 ----- Delete THIS LINE ONLY if you DONT have a DECAL. (IMPORTANT)
		door.CanCollide = true 
		door.Transparency = 0 
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

Heres the new script!
example4
So for each door and script I just have to update it and add another string value. It’ll be a pain but I do appreciate the help again!

1 Like