hello there again peoples, today I have stumbled across an yet another problem in making the game on roblox studio, so basically I wanted to make an door which have localscript that detects if localplayer have enough values stored in IntValue named “SocialCredit”, that means if player have enough social credits, the door should be open for that localplayer who have enough Values in that IntValues.
but it sucks that I doesn’t know how I can make the script work, so what I need for this situation is your help, I may show the script block and screenshot of the game, thank you so much for helping again.
local function onValueChange()
if game.Players.LocalPlayer:FindFirstChild("SocialCredit").Value >= 3 then
wait(0.1)
workspace.SocialCreditDoor1.CanCollide = false
print("the social credit door 1 has been opened")
else
workspace.SocialCreditDoor1.CanCollide = true
print("the social credit door 1 has been closed")
end
end
script.Parent:GetPropertyChangedSignal(game.Players.LocalPlayer:FindFirstChild("SocialCredit")):Connect(onValueChange)
…I have saw that specific code lines from some other people’s devforum posts, so here is the where I found the inspired source, it’s in the third reply of the post. the source of the original code (in third reply)
also here is some of the screenshot of the codes in the game. so here it is.
thank you so much for your help, I’m pleased because of your help.
-mari
Maybe you should use a Touch event inside a script instead for the door. Not sure how you would specify the player by using GetPropertyChangedSignal()
in this case, as this won’t detect if the player is at the door.
1 Like
Use .Touched event instead like this -
script.Parent.Touched:Connect(function(character)
if character:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(character)
--do whatever you want with player
end
end)
3 Likes
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
(from the documentation place)
if its not in one of those, put it in one of those.
Now, the script of yours looks correct tbh, can you tell me exactly what happens when you try to run it?
(For the previous two replies, im pretty sure OP only wants to open the door when the player receives enough points, not when they touch the door, so it should open as soon as the value changes)
2 Likes
hello there, the door that opens when player touchs the door and have enough values is alright for me, I wanna make the IntValue door work like that, and also when I used Herbz’s script it still didn’t opened when I had enough values of Social Credit, and here is the thing I checked from the output:
anyways thank you for your generous help, it helps me with big problems like this
-mari
please expand the player tab and show me what is under the local player
like r u sure “SocialCredit” exists?
Oh, I see what the reason for the error is. Assuming that SocialCredit
exists, try using this script instead:
script.Parent.Touched:Connect(function(character)
if character:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(character)
if player:FindFirstChild("SocialCredit").Value >= 3 then
wait(0.1)
workspace.SocialCreditDoor1.CanCollide = false
print("the social credit door 1 has been opened")
else
workspace.SocialCreditDoor1.CanCollide = true
print("the social credit door 1 has been closed")
end
end
end)
1 Like
yup, the “SocialCredit” does exist, but yet I do not know about that problem going on, and I also used Herbz’s new script suggestion but yet it’s still not opening…
thanks for the helps tho
-mari
1 Like
script.Parent:GetPropertyChangedSignal(game.Players.LocalPlayer:FindFirstChild("SocialCredit")):Connect(onValueChange)
GetPropertyChangedSignal requires a string, try using .Changed instead
game.Players.LocalPlayer:FindFirstChild("SocialCredit").Changed:Connect(onValueChange)
wait wait wait wait wait I just realized, that script isn’t a local script BRU
Use Herbz’s current script, but like, see if it works if you remove the .Name
@SuplierZWTF Looking at this you can see that its actually a serverscript and not a local script lol
Create a localscript, parent it to StarterPlayerScripts and use this code:
local Player = game.Players.LocalPlayer
local Value = Player:WaitForChild('SocialCredit')
local Door = workspace.SocialCreditDoor1
local function onValueChange(NewValue)
if NewValue >= 3 then
wait(0.1)
Door.CanCollide = false
print("the social credit door 1 has been opened")
else
Door.CanCollide = true
print("the social credit door 1 has been closed")
end
end
Value.Changed:Connect(onValueChange)
2 Likes
He tried it before I changed it, but it didn’t work.
weird, you shouldn’t need anything related to .Name
and he didn’t show the error BRU
1 Like
There’s a tiny bug where if value changes to 3, and back to 2 within 0.1 seconds, the cancollide will remain false
I tried it again after you changed the script, sorry I was inpatient, but yet the script did not work even through I used your fixed script, and I even tested by removing the .name), but thing isn’t showing any outputs at all ;-;
-mari
put print statements across the script and show us where it ends up at
hey there, I do have print statement looking things in the script tho, but I don’t understand to put it across the script, anyway here is the edited script. and I deleted the .Name through
-mari
bro you changed it to a localscript again, obviously it wont work ;-;
Change that to a serverscript, the script wont even run if its a local script not under a player, thats my first reply lol
yea sorry about that lol, I’m stupid sometimes.
but even through I changed it into the server script, it doesn’t seems to work, even without the .Name, and even with .Name, that’s weird
-mari
send a screenshot again, I wanna see what exactly happens now
and add in a print(player)