I’m new at scripting and this is a script I have tried looking tutorials up of and constantly skimming the dev forum to find something to help but I have honestly found nothing. I’m scripting a guessing game which I have done the script for already but the only thing I am stuck on is getting points with every guess. Since its a chatted function, I have no clue how to go about this. I have two different components which is guessing and points. I’m trying to script it where you guess one right, you get one guess “point” and then you get two points that are separate from the guesses. Here is my leaderstats that I made:
Here is my guessing script that I have for each door instance:
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)
if (msg == string.lower(thecharacter.Value)) then
door.CanCollide = false
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)
If anyone could point me in a certain direction or provide me with any sort of help that would be immensely appreciated! Thanks in advance.
I don’t think you added it to the right spot. I’m assuming
is the player.
so just add this line of code
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)
recipient.leaderstats.Guesses.Value = player.leaderstats.Guesses.Value + 1 -- Adds guess value
if (msg == string.lower(thecharacter.Value)) then
door.CanCollide = false
recipient.leaderstats.Points.Value = player.leaderstats.Points.Value + 1 -- Adds Points valu
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)
Edit: If its not then it may be speaker
replace recipient with speaker for the 2 new lines i added
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 = player.leaderstats.Guesses.Value + 1 -- Adds guess value
if (msg == string.lower(thecharacter.Value)) then
door.CanCollide = false
speaker.leaderstats.Points.Value = player.leaderstats.Points.Value + 1 -- 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)
My leaderstats is in the serverscriptstorage and the script for the guessing door is in the workplace. Do I need to move the script somewhere else? Because as of right now the player in that script is counted as an unknown global.
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 -- Adds guess value
if (msg == string.lower(thecharacter.Value)) then
door.CanCollide = false
speaker.leaderstats.Points.Value = speaker.leaderstats.Points.Value + 1 -- 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)
Nevermind i saw the problem. Try again and see it should work, if it doesn’t send me the full error.
Thanks so much! It worked. The way I was doing it before clashed with my leaderstats which is why I think I was having that problem. This really cleared things up for me. Thanks again for your help!
I didn’t know things like that could happen! I have so many scripts in my workspace that are like that. Thanks for the heads up and the help! I’ll go and fix some things right now.
Just realized you said ServerScriptStorage. Make sure you put it in ServerScriptService if you want it to run. ServerScriptStorage would be good for storing Objects.
Depends if you want to chance your scripts being stolen or not. If you plan on your game becoming popular, you’ll want to do everything you can to make sure your scripts are secure.
By the sound of Server Script, you’d think so. But they’re actually replicated to the client if they’re in Workspace, ReplicatedStorage, or a few others though.
Edit: Looking into it, it doesn’t seem to be as replicated / easily stealable as I was thinking. Not too sure honestly. Don’t take my word for it lol.
This isn’t true. Server scripts are never sent to the client, so they’re safe to be in workspace. The only thing the client knows is that they exist(and the most they can do to them is delete them if they’re in their character, e.g. the default health script). However, it’s better practice to use ServerScriptService unless you’re using a script.Parent connection to something.
So I went through and replaced the scripts for each door only to play through and realize that something is wrong with the guesses. I guess one door and it ends up, I believe, playing through all the scripts and giving me a lot of points.
As seen here, this is just with one guess. I get 586 extra guesses. The points are correct for each one but I have no idea why its giving me those many guesses.
This is where the script is in the Workplace. And I have the same script for all the doors in the workplace. I don’t see why the points work perfectly but the guesses don’t.
Edit: Should I use a FireDoorClient in ReplicatedStorage to connect the door opening script to a new guess/point leaderstats in the serverscriptservice? I did something like that for something else and it worked fine. Just not sure what else to do.
Edit2: Just realized that the guess function doesn’t work at all. I chat random things and it gives me guessing “points”. The points function is the only one that works. Idk what to do.