Value not changing

Hello! I am making a football/soccer game where I can adjust the power for shooting the ball.

Here is a script of mine:

local power = Instance.new("IntValue")

power.Name = "Power"
power.Parent = game.StarterPlayer.StarterCharacterScripts
power.Value = 1000

game.Workspace.ZFired.OnServerEvent:Connect(function()
	power.Value = 100
end)

game.Workspace.XFired.OnServerEvent:Connect(function()
	power.Value = 75
end)

game.Workspace.CFired.OnServerEvent:Connect(function()
	power.Value = 125
end)

The remote events are firing and at the top, the power is set to 1000, but it doesn’t change when the remote events fire. It’s in a server script. Please help. Thank you!

5 Likes

Try to put it in a local script

Why did you parent it to StarterCharacterScripts? I’m pretty sure nothing except scripts run there. I could be wrong, though.

I think this is what you are looking for: OnClientEvent

1 Like
local power = Instance.new("IntValue")

power.Name = "Power"
power.Parent = game.StarterPlayer.StarterCharacterScripts
power.Value = 1000

game.Workspace.ZFired.OnClientEvent:Connect(function()
        print("Z Event Fired")
	power.Value = 100
end)

game.Workspace.XFired.OnClientEvent:Connect(function()
        print("X Event Fired")
	power.Value = 75
end)

game.Workspace.CFired.OnClientEvent:Connect(function()
        print("C Event Fired")
	power.Value = 125
end)

If no prints pop up, consider reviewing the script where you fire the event.


Consider changing the “FireServer” into FireClient

Example :

game.Workspace.CFired:FireClient()

quick question why is the event in workspace

1 Like

Ah yeah, and that… If it’s a Server script, it takes OnClientEvent, not OnServerEvent

This should fix it. :slightly_smiling_face:

Changing a value located in the StarterCharacterScripts (or anywhere, where it would be replicated to players individually when they join) will not change the value for a specific player that is currently in the game. Since you put the power integer value inside the StarterCharacterScripts, a copy of it will be parented to the player’s character model when they join the game, and you should access/change that copy if you want to modify it for individual players. However, if you’re going to change the value that the players will start off with (when they join the game), you should change the value inside StarterCharacterScripts.

Thanks everyone for helping out! I managed to get it fixed.

Because IntValues don’t usually work, try doing the NumberValues, instead.

its already fixed ty for helping

I believe you are missing a “/”.
Here is the code:

local power = Instance.new(“IntValue”)

power.Name = “Power”
power.Parent = game.StarterPlayer.StarterCharacterScripts
power.Value = 1000

game.Workspace.ZFired.OnServerEvent:Connect(function()
power.Value = 100
end)

game.Workspace.XFired.OnServerEvent:Connect(function()
power.Value = 75
end)

game.Workspace.CFired.OnServerEvent:Connect(function()
power.Value = 125
end)

Also, it’s a good idea to change the value in a heartbeat script, so that the server updates the value every second.

Please stop replying to old topics. I know you’re just trying to help, but as you can see, this was already fixed.

9 Likes

Then they should mark it as solved.

Well if it’s like 9 days old with no more comments, please just let it be. Most of the time it’s already solved by the person themselves, but they can’t mark anything as solution, I suggest checking the comments.

9 Likes

They can easily mark it as a solution and that is how it lets people no its solved.

Just check the comments man, you keep commenting on every topic. I would think you have some time to do that, I’m not gonna go to all my old topics and mark it as a solution right now

9 Likes

Well then that sounds like a “you problem”, Cry about it buddy

1 Like

I don’t really mind you replying to my old topics if I’ve already solved it, since you reply to 5 topics in 1 minute with a whole story and you don’t mind either, it’s not really a problem for anyone! :slight_smile:

I just don’t want to waste your time since you are helping people out. If you want me to cry about it, you can go reply to other people’s topics since there have been a lot of topics made in the time that we are chatting.

9 Likes

Also why were you trying to force me to follow and like all of the comments of a random account?

Why not your account? And why are you targeting me for this?

9 Likes