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

Common Error: Script works in studio but doesn't run in actual game?

Asked by
Hybric 271 Moderation Voter
7 years ago
Edited 7 years ago

I coded a script that will kick a ball to a certain position on mouse that works in studio, however does not work in the actual game (the script is located in the starterGui). How do you fix this?


--[[HYBRIC KEY CONTROLS: CLICK: SHOOT, A COUNTER VALUE WILL DETERMINE THE POWER/VELOCITY OF BALL ]] Master = game.Players.LocalPlayer mouse = Master:GetMouse() local minShotValue = 10 local maxValue = 20 local isHold = false local TelePos = Master.Character.Humanoid.TargetPoint local targetPos = mouse.Hit.p local DEBOUNCE = false function l()--indicate you have began trick shot if (game.Players[Master.Name] ~= nil) then game.Players[Master.Name].PlayerGui.isDoingTrick.Value = true end end function l2()--indicate you have began trick shot if (game.Players[Master.Name] ~= nil) then game.Players[Master.Name].PlayerGui.isDoingTrick.Value = false end end function update() if (game.Players[Master.Name] ~= nil) then game.Players[Master.Name].PlayerGui.isDoingTrick.shooting.customPower.Value = minShotValue end end mouse.Button1Up:connect(function(mouse_up) --Hold Mouse if (not DEBOUNCE) then DEBOUNCE=true l() print("MOUSE DOWN") minShotValue = 0; game.Players[Master.Name].PlayerGui.isDoingTrick.Value = false game.Players[Master.Name].PlayerGui.isDoingTrick.shooting.Value = false game.Players[Master.Name].PlayerGui.shootingGui.Frame.Visible = false game.Players[Master.Name].PlayerGui.shootingGui.Frame.sizer.Size = UDim2.new(0,0,1,0); DEBOUNCE = false; --i have to script a reset value when the ball gets hit end end) mouse.Button1Down:connect(function(mouse_down) --Hold Mouse if (not DEBOUNCE) then DEBOUNCE=true l() print("MOUSE UP") minShotValue = 1 local hitLoc = game.Lighting.shotT:Clone() hitLoc.Parent = game.Players[Master.Name].PlayerGui game.Players[Master.Name].PlayerGui.isDoingTrick.shooting.Value = true; game.Players[Master.Name].PlayerGui.shootingGui.Frame.Visible = true; game.Players[Master.Name].PlayerGui.beforeKick:Clone().Parent = game.Players[Master.Name].Character --game.Players[Master.Name].Character.beforeKick:Play() while minShotValue<=maxValue and workspace.soccerBall.justTouched.Value == false do game.Players[Master.Name].PlayerGui.isDoingTrick.shooting.hitPos.Value = hitLoc.Position hitLoc.Position = mouse.hit.p game.Players[Master.Name].PlayerGui.shootingGui.Frame.sizer.Size = UDim2.new(minShotValue/maxValue,0,1,0); wait(0.1) minShotValue = minShotValue + 1 update() --print(""..minShotValue) end wait(1) game.Players[Master.Name].PlayerGui.isDoingTrick.Value = false game.Players[Master.Name].PlayerGui.isDoingTrick.shooting.Value = false wait(2) game.Players[Master.Name].PlayerGui.shootingGui.Frame.Visible = false game.Players[Master.Name].PlayerGui.shootingGui.Frame.sizer.Size = UDim2.new(0,0,1,0); hitLoc:remove() wait() DEBOUNCE=false end --i have to script a reset value when the ball gets hit end) mouse.KeyDown:connect(function(key) key:lower() local TelePos = Master.Character.Humanoid.TargetPoint local targetPos = mouse.Hit.p if key == "q" then end end)

Output:

Players.Hybric.PlayerGui.skillShots:10: attempt to index field 'Character' a nil value

im assuming i need to do waitforchild method

1
Post code please. Goulstem 8144 — 7y
0
posted Hybric 271 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

I assume this is a LocalScript. LocalScripts are rather fast, and spawning a player in the world can be quite slow. I would recommend you do this:

local plrChar = Master.Character:wait()
local TelePos = plrChar.Humanoid:WaitForChild("TargetPoint")

Take a look and see if it works.

0
Thanks but I realized that already Hybric 271 — 7y
Ad

Answer this question