Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does Remote Function not seem to change value?

I recently made this script, it's basically a core for changing stats from local scripts. The game is Filtering Enabled. When invoked, it'll send over the value it wants to change and what the value is. But whenever valuename is "Health", "Strength", "Speed", "Kagune", "Quinque" it says it's a nil value, the error occured at line 10 i think. Even though there is a value in playerdata. It only seems to work when the valuename is "Playing"

local replicatedstorage = game.ReplicatedStorage
local remoteinstance = replicatedstorage:WaitForChild("RemoteInstance")
local gamedata = replicatedstorage:WaitForChild("GameData")
local remote = remoteinstance:WaitForChild("ChangeStat")

--Variables

function remote.OnServerInvoke(player, valuename, value)
	local playerdata = player:WaitForChild("BaseValue")
	if valuename == "Health" or "Strength" or "Speed" or "Kagune" or "Quinque" then
		if playerdata:FindFirstChild("SkillPoint").Value > 0 then
			if gamedata:WaitForChild(valuename).Value > playerdata:WaitForChild(valuename).Value then
		playerdata:FindFirstChild("SkillPoint").Value = playerdata:FindFirstChild("SkillPoint").Value - 1
		playerdata:FindFirstChild(valuename).Value = playerdata:FindFirstChild(valuename).Value + 1		
			else
print("Max Stats!")						
			end
		end	
	end
	
	if valuename == "Playing" then
		playerdata:WaitForChild(valuename).Value = value
	else
		
		playerdata:WaitForChild(valuename).Value = value
end
	end

3 comments

0

Nevermind the error occured at Line 12.

0

It also seems like it does subtract one SkillPoint

0

where is the link that calls for ur function?

1 answer

✓ Accepted answer

One problem that I see straight away is on Line 10:

   if valuename == "Health" or "Strength" or "Speed" or "Kagune" or "Quinque" then

Lua does not understand what you put through there, and will automatically return true. What you want to do is this:

   if valuename == "Health" or valuename == "Strength" or valuename == "Speed" or valuename == "Kagune" or valuename == "Quinque" then

If does not fix your problem, Comment and I'll edit.

1 comment

0

That fixed the problem! I also added in some elseifs but yea it's fixed! Thanks alot :D

This discussion is preserved as it was. New answers, comments, and votes are closed.