New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

# UserInputService. Is my syntax broken?

Please someone help me why this things is not working well. I am trying my best but i dont know how to fix it. Thank you :D

--//Starterpack Local Script\\--
repeat wait() until game.Players.LocalPlayer.Character

local player = game.Players.LocalPlayer
local userinputservice = game:GetService("UserInputService")
local char = player.Character

userinputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://04480814830"
PlayAnim:Play()
wait(3)
end
end)


--//ServerScriptService Script\\--
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("PowerStats") --

local folder = Instance.new("Folder", plr)
local power = Instance.new("IntValue", folder)
power.Name = "Pow"
power.Value = ds:GetAsync(plr.UserId) or 0
power.Changed:Connect(function()
ds:SetAsync(plr.UserId, power.Value)
end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
end)

1
What’s not working...? Feahren 1772 — 13d
1
^ Doesn't seem to be an error with UserInputService. Probably the code within the event. suspectshot108 420 — 12d
0
did you make the animation you're using? Gnossien 131 — 12d

0

So, the problem is, you are trying to access ServerScriptService in a LocalScript, however LocalScripts, cannot access server only instances, hence the names containing "Server", try storing your leaderstats in ReplicatedStorage, where both the client and the server can retrieve data.

0

I think the problem is that on the 2nd script (line 6), you inserted something named "leaderstats" into the player, but in the 1st script at line 7, you got that "leaderstats" in the ServerScriptService. Also, you inserted in that leaderstats a IntValue named "Pow", but in the 1st script you wrote "leaderstats.Power", although it was named "Pow".

There is another error. In the 15th line in the 1st script, you added 1 to the value of "Pow". But you wrote this in a local script. So it will not change the value of "Pow". To do this, you have to send a signal from that localscript to a normal script with a remote event. Insert a remoteEvent in ReplictedStorage (name it whatever you want) and insert a normal script into Workspace.

So you can replace your 1st script by this:

repeat
wait()
until game.Players.LocalPlayer.Character

local player = game.Players.LocalPlayer
local userinputservice = game:GetService("UserInputService")
local char = player.Character

userinputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://04480814830"
PlayAnim:Play()
game.ReplicatedStorage:WaitForChild(WHATEVER YOU NAMED THE REMOTE EVENT):FireServer() -- gives a signal
wait(3)
end
end)


Then, in the normal script you inserted in Workspace, write this:

game.ReplicatedStorage:WaitForChild(WHATEVER YOU NAMED THE REMOTE EVENT).OnServerEvent:Connect(function(player) -- gets the signal and the player
end)


You don't need to make any changes in the script in the ServerScriptService.

Just to make sure, in the local script (1st script), I don't know why you added a wait(3) at the end of it. If you want to let the player click "e" again before the animation finishes, you have to add a debounce. Replace that 1st script I wrote earlier by this:

repeat
wait()
until game.Players.LocalPlayer.Character

local player = game.Players.LocalPlayer
local userinputservice = game:GetService("UserInputService")
local char = player.Character
local debounce = false

userinputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if debounce == false then -- checks if debounce is false
debounce = true
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://04480814830"