Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Temperature script not working; what is the problem?

Asked by 4 years ago

I'm trying to make a script that mimics temperature by assigning an IntValue to players so it may measure the amount of heat they receive. As shown in the script below, I'm trying to make it so whenever players are within a certain distance of a heat source, their temperature IntValue increases by one, and when they leave the radius, that increase is removed. I thought what I have would work, but it doesn't work as I thought it would.

01local Players = game:GetService("Players")
02local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
03local char = player.Character or player.CharacterAdded:Wait()
04 
05local fire = workspace.Heat
06local warmDist = 12
07 
08local temp = game.ReplicatedStorage:WaitForChild(player.Name):WaitForChild("Temp")
09 
10local inside = false
11 
12while true do
13    wait(1)
14    local distance = (char.HumanoidRootPart.Position - fire.Position).magnitude
15    if distance <= warmDist then
View all 30 lines...
0
uh maybe try a regular script BulletproofVast 1033 — 4y
0
u sure men localplayer cant access in script Xapelize 2658 — 4y
0
This script is a local script, the script below is just a normal script. Searching for localplayer in the script below is definitely a problem I didn't notice before, but it should've worked for the localscirpt. ChirpPerson 74 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

I tried to turn the localscript into a normal script yet it still didn't work. Here's what I had with the adjusts I made:

01local Players = game:GetService("Players")
02local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
03local char = player.Character or player.CharacterAdded:Wait()
04 
05local fire = workspace.Heat
06local warmDist = 12
07 
08local tempVal = game.ReplicatedStorage:WaitForChild(player.Name):WaitForChild("Temp").Value
09local tempCheck = game.ReplicatedStorage.RemoteEvents.Temperature
10 
11local inside = false
12 
13while true do
14    wait(1)
15    local distance = (char.HumanoidRootPart.Position - fire.Position).magnitude
View all 33 lines...
0
You don't need to make two wait for child(s) in line 8, just put 1 wait for child. change the wait for child temp to .Temp only Xapelize 2658 — 4y
0
ALSO ALSO ALSO i dont recommend using elseif in this kind of if statement, because it is just 2 if things (in function) just use if-else Xapelize 2658 — 4y
0
also while true do loop make the function stuck lol Xapelize 2658 — 4y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

So you should try this for a LocalScript, because you need to access LocalScript (it depends, but I'd recommend localscript)

Well I stated in the comment, while true do loop stuck the function to update the temperature. What you are gonna do is like this:

01local Players = game:GetService("Players")
02local player = Players.LocalPlayer -- it makes me confuse about using or things in these variables
03local char = player.Character
04 
05local fire = workspace.Heat
06local warmDist = 12
07 
08local tempVal = game.ReplicatedStorage:WaitForChild(player.Name):WaitForChild("Temp").Value
09local tempCheck = game.ReplicatedStorage.RemoteEvents.Temperature
10 
11while wait(1) do
12    local distance = (char.HumanoidRootPart.Position - fire.Position).magnitude
13    if distance <= warmDist then
14        tempVal = tempVal+1
15    else
16        tempVal = tempVal-1
17    end
18end

I had changed to my own version using the things i stated in comment, also gtg bye i dont know what to make this as an outro so bye bye

0
Thank you so much for your help! This is a big help to me and I'll build off this! ChirpPerson 74 — 4y
0
No problemo Xapelize 2658 — 4y

Answer this question