Hello everyone, so i am making a guessing game but i have encountered some problems i need to fix. A brief description of the game is you have to choose the correct door. What i want is that when a player chooses the correct door, only him can see it and not other players. I team test the game and when my friend chose the correct correct, i was able to see it but i want it so only him him can see it. I hope i explained it clearly so please i need help with that thank you. (Also some info, what i mean by âchoosesâ is when he touches the correct door, it becomes and transparent and he can pass through it, i want it so he can only see it himself) To make it even more clearer, it is like this game: Guess the Logo Quiz for Admin - Roblox
Assuming u guess the right answer by walking in the correct door and youâre probably doing it using .Touched event, now the reason why u can see the door when ur friend answers correctly is most probably because ur doing the .Touched event in a server script, in order to fix this and make the changes only happen to the you (locally) you should make the script local and put it in startercharacterscript then whenver the player that answers correctly will be the only one able to see the changes
I will show you the script i use in question because it is in workspace and in the block
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
end
end)
yeah so there youâre using a server script instead insert a local script inside of âCorrect2â and just copy paste the code there, dont forget to remove the existing script
yup like that, if that works out, make sure to solution this and thanks
It didnât work, i tested it with an alt account on teamtest and when i went touched it my other alt could see it.
oh yeah sorry if forgot to tell u, u had to check if the player that hit the correct door is u in order to do this u have to do:
script.Parent.Touched:Connect(function(hit)
local hit_player = hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) -- get the player that hit
if hit.Parent:FindFirstChild("Humanoid") and hit_player == game.Players.LocalPlayer then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
end
end)
any errors, if not, try printing hit_player and lemme know
why are you using and in
local hit_player = hit.Player and game.Players:GetPlayerFromCharacter(hit.Parent)
why do you have that second âandâ statement?
and game.Players:GetPlayerFromCharacter(hit.Parent) -- get the player that hit
if itâs removed then the script should work normally
its to check if hit.Parent exists and if it does get a player out of it
thats not the reason why its not working
it is, you canât use the âandâ statement with variables
a .Touched event also canât be detected by a LocalScript
hereâs what @TheCoolBaconHairIsMe needs to do:
1) Create a folder containing the guessable objects with folders for the correct and incorrect ones
2) Since LocalScripts canât handle a .Touched event, we need a RemoteEvent to send the message from a ServerScript to the LocalScript.
3) He needs a script to handle everything server-side and use the RemoteEvent to message the LocalScript so it only renders on the client.
for _, correctAnswer in pairs(game.Workspace.Guessables.Correct:GetChildren()) do
-- Searched all correct answers
correctAnswer.Touched:Connect(function(hit)
-- Correct answer is touched
if hit.Parent:FindFirstChild("Humanoid") then -- correctAnswer is hit by a player
game.ReplicatedStorage:FindFirstChild("CorrectAnswer"):FireClient(game.Players:GetPlayerFromCharacter(hit.Parent), correctAnswer) -- fires RemoteEvent "CorrectAnswer" from Server -> Client
end
end)
end
4) Lastly, we also need to have a LocalScript in the StarterPlayerScripts that receives the RemoteEvent from the ServerScript and lets the player go through the correct object.
game.ReplicatedStorage:FindFirstChild("CorrectAnswer").OnClientEvent:Connect(function(correctAnswer)
-- ClientEvent recieved from Server => lets player through correct object
correctAnswer.Transparency = 0.5
correctAnswer.CanCollide = false
task.wait(1)
correctAnswer.Transparency = 0
correctAnswer.CanCollide = true
end)
you can use âandâ statements with variable u can test it out for urself
and .Touched def works for local scripts, it wouldnt make sense if it didnt
It worked! Iâm so happy thank you so much, please keep in contact with me and add me on roblox for some chats.
I also found a way to make multiple of them thank you so much, no errors to, waiting for your reply to close this page. Also thank you @capsori for the help you contributed too, very appreciated!