Need some help with scripting!

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
image

4 Likes

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

2 Likes

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)

1 Like

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


Like this?

1 Like

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.
image

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)


When my main touches the block, nothing happens. So do my alt.

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.
image

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.
image

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!

1 Like

yeah you’re right about ‘and’ working with variables, but even then, why?

anyway, .Touched literally doesn’t work on the client-side, i’ve tried it out myself, and google says the same:


you need a serverscript for it, and if you want what OP asked (which is to