So I’m trying to make this script make it so it only works for a single person, so once the object is on touch with player it will disappear for only that player that triggered it, with everyone else still being able to trigger it themselves (Including the audio, which also triggers for everyone near the object)
Trying to make the script only work for one person when they touch the object. Once a single player crosses it, the object disappears for every other player than comes by it.
I’ve tried a few ways of changing the script up by making changes to local player and changing a few parts by frankensteining a few other scripts into it.
local Monster = game.Workspace.RickeyRat1
local Jumpscaresound = script.Parent.Parent:WaitForChild("Laughing")
triggerjumpscare1.Touched:Connect(function(hit)
local humanoid = hit.Parent.Humanoid
if humanoid then
triggerjumpscare1:Destroy()
Jumpscaresound:Play()
wait(0)
Monster.Parent = game.ReplicatedStorage
end
end)```
You will want to do this in a local script. I assume the code you provided is a local script located in StarterPlayerScripts.
The reason that your code is making it happen for everyone is because the code does not check to see if the player that touches it is the local player.
local Monster = game.Workspace.RickeyRat1
local Jumpscaresound = script.Parent.Parent:WaitForChild("Laughing")
local player = game.Players.LocalPlayer
triggerjumpscare1.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local hitPlayer = game.Players:GetPlayerFromCharacter(character)
if hitPlayer == player and humanoid then
triggerjumpscare1:Destroy()
Jumpscaresound:Play()
wait(0)
Monster.Parent = game.ReplicatedStorage
end
end)
Alright so I’ve done a quick test and now it doesn’t trigger anything (Keeping the “Monster” in-game, isn’t disappearing). I do have the script as a “local script” and it is in StarterPlayerScrips, one key aspect that I think might have made it stop working are the objects, “triggerjumpscare1” which is a part inside workspace and, "Monster being a group of an object inside Workspace.
I did end up making a quick “variable” (I’m not sure what it’s called) below line 1
local triggerjumpscare1 = game.Workspace.TriggerJumpscare1
This didn’t do anything after trying that out, is there something I should do about the objects to somehow make it work again with it’s new addition of it including localplayers?
First I would see if the touch function is firing. I would do this by adding some print functions both outside and inside of the if statement.
triggerjumpscare1.Touched:Connect(function(hit)
print("touched") -- added to see if the function runs
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local hitPlayer = game.Players:GetPlayerFromCharacter(character)
if hitPlayer == player and humanoid then
print("player touched") -- added to see if the boolean statement is true
triggerjumpscare1:Destroy()
Jumpscaresound:Play()
wait(0)
Monster.Parent = game.ReplicatedStorage
end
end)
The fix will be easier to find if we know what parts of the code is working and what is not.
If the first print statement doesn’t run, then it’s an issue with the touched event.
If it’s only the second print that doesn’t run, then it’s an issue with the if statement.
If they both print, then it’s an issue with the code inside the if statement.
Wish I could be of more help but try running it with the prints and see which ones run.
Thank you! I was able to resolve the problem after finding that line 4’s, “Laughing” sound variable was the issue, with it not being the “Parent.Parent”. I was able to switch it to…